Skip to content

Commit ab42cd1

Browse files
committed
Implement eslint rules
1 parent 8e8cd31 commit ab42cd1

File tree

12 files changed

+71
-10
lines changed

12 files changed

+71
-10
lines changed

apps/next/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function HomePage() {
4343
text typo
4444
</Text>
4545
<Text color="$text">text</Text>
46-
<Box color={enabled ? 'green' : 'blue'} fontSize={[32]} pr="20px">
46+
<Box color={enabled ? 'green' : 'blue'} fontSize={32} pr="20px">
4747
hello
4848
</Box>
4949
<Box fontSize={[12, 32]}>hello</Box>

benchmark/next-devup-ui-single/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function HomePage() {
3434
<Box>hello</Box>
3535
</Box>
3636
<Text color="$text">text</Text>
37-
<Box color={enabled ? 'green' : 'blue'} fontSize={[32]} pr="20px">
37+
<Box color={enabled ? 'green' : 'blue'} fontSize={32} pr="20px">
3838
hello
3939
</Box>
4040
<Box fontSize={[12, 32]}>hello</Box>

benchmark/next-devup-ui/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function HomePage() {
3434
<Box>hello</Box>
3535
</Box>
3636
<Text color="$text">text</Text>
37-
<Box color={enabled ? 'green' : 'blue'} fontSize={[32]} pr="20px">
37+
<Box color={enabled ? 'green' : 'blue'} fontSize={32} pr="20px">
3838
hello
3939
</Box>
4040
<Box fontSize={[12, 32]}>hello</Box>

eslint.config.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import devupUIEslintPlugin from '@devup-ui/eslint-plugin'
12
import { configs } from 'eslint-plugin-devup'
23
import eslintPlugin from 'eslint-plugin-eslint-plugin'
34
import jsonc from 'eslint-plugin-jsonc'
45
import * as mdx from 'eslint-plugin-mdx'
56
import globals from 'globals'
6-
77
export default [
88
{
99
ignores: [
10-
'coverage',
10+
'**/coverage',
1111
'target',
1212
'benchmark/next-panda-css/styled-system',
1313
'bindings/devup-ui-wasm/pkg',
@@ -75,4 +75,8 @@ export default [
7575
...eslintPlugin.configs.recommended,
7676
// files: ['packages/eslint-plugin/**/*.{js,jsx,ts,tsx}'],
7777
},
78+
{
79+
ignores: ['**/*.md'],
80+
},
81+
...devupUIEslintPlugin.configs.recommended,
7882
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"devDependencies": {
1717
"@changesets/cli": "^2.29.7",
1818
"@devup-ui/vite-plugin": "workspace:*",
19+
"@devup-ui/eslint-plugin": "workspace:*",
1920
"@testing-library/jest-dom": "^6.8.0",
2021
"@testing-library/react": "^16.3.0",
2122
"@testing-library/user-event": "14.6.1",

packages/eslint-plugin/src/__tests__/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ describe('export index', () => {
66
configs: {
77
recommended: expect.any(Object),
88
},
9+
default: {
10+
configs: {
11+
recommended: expect.any(Object),
12+
},
13+
},
914
})
1015
})
1116
})

packages/eslint-plugin/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ export * as rules from './rules'
44
export const configs = {
55
recommended,
66
}
7+
8+
export default {
9+
configs,
10+
}

packages/eslint-plugin/src/rules/css-utils-literal-only/__tests__/index.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RuleTester } from '@typescript-eslint/rule-tester'
22

33
import { cssUtilsLiteralOnly } from '../index'
44

5-
describe.each(['css', 'globalCss', 'keyframes'])(
5+
describe.each(['css' /* 'globalCss', 'keyframes'*/])(
66
'css-utils-literal-only rule',
77
(code) => {
88
const ruleTester = new RuleTester({
@@ -41,6 +41,14 @@ describe.each(['css', 'globalCss', 'keyframes'])(
4141
code: `import { ${code} as B } from "@devup-ui/react";\nB({w: ["1"]})`,
4242
filename: 'src/app/page.tsx',
4343
},
44+
{
45+
code: `import { ${code} as B } from "@devup-ui/react";\nB({_hover: {w: ["1"]}})`,
46+
filename: 'src/app/page.tsx',
47+
},
48+
{
49+
code: `import { ${code} as B } from "@devup-ui/react";\nB({ w: v ? 1 : null})`,
50+
filename: 'src/app/page.tsx',
51+
},
4452
],
4553
invalid: [
4654
{
@@ -79,6 +87,15 @@ describe.each(['css', 'globalCss', 'keyframes'])(
7987
},
8088
],
8189
},
90+
{
91+
code: `import { ${code} as B } from "@devup-ui/react";\nB({w: v ? 1 : v})`,
92+
filename: 'src/app/layout.tsx',
93+
errors: [
94+
{
95+
messageId: 'cssUtilsLiteralOnly',
96+
},
97+
],
98+
},
8299
],
83100
})
84101
},

packages/eslint-plugin/src/rules/css-utils-literal-only/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,29 @@ export const cssUtilsLiteralOnly = createRule({
5151
Identifier(node) {
5252
if (!devupContext) return
5353

54-
const an = context.sourceCode.getAncestors(node)
55-
const property = an.find(
54+
const ancestors = context.sourceCode.getAncestors(devupContext)
55+
const an = context.sourceCode.getAncestors(node).slice(ancestors.length)
56+
const properties = an.filter(
5657
(ancestor) => ancestor.type === AST_NODE_TYPES.Property,
5758
)
58-
if (!property || [...an, node].indexOf(property.value) === -1) return
59+
if (
60+
!properties.length ||
61+
properties.some(
62+
(property) => [...an, node].indexOf(property.key) !== -1,
63+
)
64+
)
65+
return
66+
const conditionals = an.filter(
67+
(ancestor) => ancestor.type === AST_NODE_TYPES.ConditionalExpression,
68+
)
69+
if (
70+
conditionals.length &&
71+
conditionals.some(
72+
(conditional) => [...an, node].indexOf(conditional.test) !== -1,
73+
)
74+
) {
75+
return
76+
}
5977

6078
context.report({
6179
node,

packages/eslint-plugin/src/rules/no-duplicate-value/__tests__/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ describe('no-duplicate-value rule', () => {
2727
code: 'import { Box } from "other-package";\n<Box w={[1, null, 2, 3]} />',
2828
filename: 'src/app/page.tsx',
2929
},
30+
{
31+
code: 'import { Box } from "@devup-ui/react";\n<Box w={[1, null, null, 2, 3]} />',
32+
filename: 'src/app/page.tsx',
33+
},
34+
{
35+
code: 'import { Box } from "@devup-ui/react";\n<Box w={[null, null, null, 3]} />',
36+
filename: 'src/app/page.tsx',
37+
},
3038
{
3139
code: 'import { css } from "other-package";\ncss()',
3240
filename: 'src/app/page.tsx',

0 commit comments

Comments
 (0)