Skip to content

Commit

Permalink
Merge branch 'master-co:dev/beta' into dev/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
0Miles authored Oct 25, 2023
2 parents 4b8e24f + f916e4b commit 8079eb3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
9 changes: 6 additions & 3 deletions docs/code-linting/content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import Features, { Feature } from 'shared/components/Features'
<Feature>
<IconFunction className="app-icon-primary" />
<div>
**[Supports CSS-in-JS](#supports-css-in-js)**
**[Supports JS utilities](#supports-js-utilities)**

Avoid declaring the identical CSS property repeatedly
Check the classes in popular utility arguments
</div>
</Feature>
</Features>
Expand Down Expand Up @@ -115,4 +115,7 @@ export default {
### Conflicting class checks 🚧
Soon...

### Supports CSS-in-JS
### Supports JS utilities
<video className="aspect:2/1 r:5 max-w:xs" autoPlay loop muted playsInline>
<source src="/videos/supports-js-utilities.webm" type="video/webm" />
</video>
10 changes: 9 additions & 1 deletion docs/eslint/content.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defaultConfigurationScript from '../../packages/eslint-config/index.js?text'
import defaultSettings from '../../packages/eslint-plugin/lib/settings.js?text'

## Usage [sr-only]

Expand Down Expand Up @@ -43,4 +44,11 @@ Set `disallowTraditionalClass: true` to disallow using traditional classes:
}]
}
}
```
```

---

## Settings
<Code lang="js">
{defaultSettings}
</Code>
2 changes: 1 addition & 1 deletion examples/eslint/clsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import React from 'react'
import clsx from 'clsx'

export default () => (
<h1 className={clsx('text-align:cente')}>Hello World</h1>
<h1 className={clsx('display:bloc')}>Hello World</h1>
)
4 changes: 1 addition & 3 deletions examples/eslint/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ import { styled } from '@master/css.react'

const H1 = styled.h1`text-align:cente`

export default () => (
<H1>Hello World</H1>
)
export default () => <H1>Hello World</H1>
4 changes: 2 additions & 2 deletions packages/eslint-plugin/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const settings = {
functions: ['classnames', 'clsx', 'ctl', 'cva', 'cv', 'classVariant', 'styled(?:\\.\\w+)?'],
ignoredKeys: ['compoundVariants', 'defaultVariants'],
calleeMatching: '^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)',
classMatching: '^class(Name)?$',
ignoredKeys: ['compoundVariants', 'defaultVariants'],
config: 'master.css.*'
}

Expand Down
10 changes: 0 additions & 10 deletions packages/eslint-plugin/lib/utils/ast.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@

const separatorRegEx = /([\t\n\f\r ]+)/

function calleeToString(calleeNode) {
if (calleeNode.type === 'Identifier') {
return calleeNode.name
}
if (calleeNode.type === 'MemberExpression') {
return `${calleeNode.object.name}.${calleeNode.property.name}`
}
}

function extractRangeFromNode(node) {
if (node.type === 'TextAttribute' && node.name === 'class') {
return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset]
Expand Down Expand Up @@ -252,7 +243,6 @@ function findLoc(text, lines, startLine, endLine) {
}

module.exports = {
calleeToString,
extractRangeFromNode,
extractValueFromNode,
extractClassnamesFromValue,
Expand Down
13 changes: 9 additions & 4 deletions packages/eslint-plugin/lib/utils/define-visitors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const astUtil = require('./ast')

function defineVisitors({ context, settings }, visitNode) {

const isFnNode = (node) => {
const calleeStr = astUtil.calleeToString(node.callee || node.tag)
return settings.functions.findIndex((eachFnPattern) => new RegExp('^' + eachFnPattern).test(calleeStr)) !== -1
let calleeName = ''
const calleeNode = node.callee || node.tag
if (calleeNode.type === 'Identifier') {
calleeName = calleeNode.name
}
if (calleeNode.type === 'MemberExpression') {
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`
}
return new RegExp(settings.calleeMatching).test(calleeName)
}

const CallExpression = function (node) {
Expand Down

0 comments on commit 8079eb3

Please sign in to comment.