Skip to content

Commit 8c928df

Browse files
committed
chore: add whitelist to rules
1 parent 0dd3999 commit 8c928df

11 files changed

+168
-20
lines changed

.changeset/eight-pigs-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@pandacss/eslint-plugin': patch
3+
---
4+
5+
Add whitelist option to rules

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ Where rules are included in the configs `recommended`, or `all` it is indicated
123123
| [`@pandacss/no-important`](docs/rules/no-important.md) | |
124124
| [`@pandacss/no-invalid-token-paths`](docs/rules/no-invalid-token-paths.md) | ✔️ |
125125
| [`@pandacss/no-invalid-nesting`](docs/rules/no-invalid-nesting.md) | ✔️ |
126-
| [`@pandacss/no-margin-properties`](docs/rules/no-margin-properties.md) | |
127-
| [`@pandacss/no-physical-properties`](docs/rules/no-physical-properties.md) | |
126+
| [`@pandacss/no-margin-properties`](docs/rules/no-margin-properties.md) ⚙️ | |
127+
| [`@pandacss/no-physical-properties`](docs/rules/no-physical-properties.md) ⚙️ | |
128128
| [`@pandacss/no-property-renaming`](docs/rules/no-property-renaming.md) | ✔️ |
129129
| [`@pandacss/no-unsafe-token-fn-usage`](docs/rules/no-unsafe-token-fn-usage.md) | ✔️ |
130-
| [`@pandacss/prefer-longhand-properties`](docs/rules/prefer-longhand-properties.md) | |
131-
| [`@pandacss/prefer-shorthand-properties`](docs/rules/prefer-shorthand-properties.md) | |
132-
| [`@pandacss/prefer-atomic-properties`](docs/rules/prefer-atomic-properties.md) | |
133-
| [`@pandacss/prefer-composite-properties`](docs/rules/prefer-composite-properties.md) | |
130+
| [`@pandacss/prefer-longhand-properties`](docs/rules/prefer-longhand-properties.md) ⚙️ | |
131+
| [`@pandacss/prefer-shorthand-properties`](docs/rules/prefer-shorthand-properties.md) ⚙️ | |
132+
| [`@pandacss/prefer-atomic-properties`](docs/rules/prefer-atomic-properties.md) ⚙️ | |
133+
| [`@pandacss/prefer-composite-properties`](docs/rules/prefer-composite-properties.md) ⚙️ | |
134134
| [`@pandacss/prefer-unified-property-style`](docs/rules/prefer-unified-property-style.md) | |
135135

136136
## Settings

plugin/src/rules/no-hardcoded-color.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ const rule: Rule = createRule({
2929
noOpacity: {
3030
type: 'boolean',
3131
},
32+
whitelist: {
33+
type: 'array',
34+
items: {
35+
type: 'string',
36+
minLength: 0,
37+
},
38+
uniqueItems: true,
39+
},
3240
},
3341
additionalProperties: false,
3442
},
@@ -37,13 +45,15 @@ const rule: Rule = createRule({
3745
defaultOptions: [
3846
{
3947
noOpacity: false,
48+
whitelist: [],
4049
},
4150
],
4251
create(context) {
4352
const noOpacity = context.options[0]?.noOpacity
53+
const whitelist: string[] = context.options[0]?.whitelist ?? []
4454

4555
// Caches for isColorToken and isColorAttribute results
46-
const colorTokenCache = new Map<string, boolean | undefined>()
56+
const colorTokenCache = new Map<string, boolean | undefined>(whitelist?.map((item) => [item, true]))
4757
const colorAttributeCache = new Map<string, boolean>()
4858

4959
// Cached version of isColorToken

plugin/src/rules/no-margin-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,31 @@ const rule: Rule = createRule({
1717
'Use flex or grid with the `gap` property to define spacing in parent elements for a more resilient layout.',
1818
},
1919
type: 'suggestion',
20-
schema: [],
20+
schema: [
21+
{
22+
type: 'object',
23+
properties: {
24+
whitelist: {
25+
type: 'array',
26+
items: {
27+
type: 'string',
28+
minLength: 0,
29+
},
30+
uniqueItems: true,
31+
},
32+
},
33+
additionalProperties: false,
34+
},
35+
],
2136
},
22-
defaultOptions: [],
37+
defaultOptions: [
38+
{
39+
whitelist: [],
40+
},
41+
],
2342
create(context) {
43+
const whitelist: string[] = context.options[0]?.whitelist ?? []
44+
2445
// Cache for resolved longhand properties
2546
const longhandCache = new Map<string, string>()
2647

@@ -41,6 +62,7 @@ const rule: Rule = createRule({
4162
}
4263

4364
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier) => {
65+
if (whitelist.includes(node.name)) return
4466
if (!isMarginProperty(node.name)) return
4567

4668
context.report({

plugin/src/rules/no-physical-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,31 @@ const rule: Rule = createRule({
1919
},
2020
type: 'suggestion',
2121
hasSuggestions: true,
22-
schema: [],
22+
schema: [
23+
{
24+
type: 'object',
25+
properties: {
26+
whitelist: {
27+
type: 'array',
28+
items: {
29+
type: 'string',
30+
minLength: 0,
31+
},
32+
uniqueItems: true,
33+
},
34+
},
35+
additionalProperties: false,
36+
},
37+
],
2338
},
24-
defaultOptions: [],
39+
defaultOptions: [
40+
{
41+
whitelist: [],
42+
},
43+
],
2544
create(context) {
45+
const whitelist: string[] = context.options[0]?.whitelist ?? []
46+
2647
// Cache for resolved longhand properties
2748
const longhandCache = new Map<string, string>()
2849

@@ -68,6 +89,7 @@ const rule: Rule = createRule({
6889
}
6990

7091
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier) => {
92+
if (whitelist.includes(node.name)) return
7193
const longhandName = getLonghand(node.name)
7294
if (!(longhandName in physicalProperties)) return
7395

plugin/src/rules/prefer-atomic-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,31 @@ const rule: Rule = createRule({
1616
atomic: 'Use atomic properties instead of `{{composite}}`. Prefer: \n{{atomics}}',
1717
},
1818
type: 'suggestion',
19-
schema: [],
19+
schema: [
20+
{
21+
type: 'object',
22+
properties: {
23+
whitelist: {
24+
type: 'array',
25+
items: {
26+
type: 'string',
27+
minLength: 0,
28+
},
29+
uniqueItems: true,
30+
},
31+
},
32+
additionalProperties: false,
33+
},
34+
],
2035
},
21-
defaultOptions: [],
36+
defaultOptions: [
37+
{
38+
whitelist: [],
39+
},
40+
],
2241
create(context) {
42+
const whitelist: string[] = context.options[0]?.whitelist ?? []
43+
2344
// Cache for resolved longhand properties
2445
const longhandCache = new Map<string, string>()
2546

@@ -87,6 +108,7 @@ const rule: Rule = createRule({
87108
}
88109

89110
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier, composite: string) => {
111+
if (whitelist.includes(node.name)) return
90112
const atomics = compositeProperties[composite].map((name) => `\`${name}\``).join(',\n')
91113

92114
context.report({

plugin/src/rules/prefer-composite-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,31 @@ const rule: Rule = createRule({
1616
composite: 'Use composite property instead of `{{atomic}}`. Prefer: `{{composite}}`.',
1717
},
1818
type: 'suggestion',
19-
schema: [],
19+
schema: [
20+
{
21+
type: 'object',
22+
properties: {
23+
whitelist: {
24+
type: 'array',
25+
items: {
26+
type: 'string',
27+
minLength: 0,
28+
},
29+
uniqueItems: true,
30+
},
31+
},
32+
additionalProperties: false,
33+
},
34+
],
2035
},
21-
defaultOptions: [],
36+
defaultOptions: [
37+
{
38+
whitelist: [],
39+
},
40+
],
2241
create(context) {
42+
const whitelist: string[] = context.options[0]?.whitelist ?? []
43+
2344
// Cache for resolved longhand properties
2445
const longhandCache = new Map<string, string>()
2546

@@ -85,6 +106,7 @@ const rule: Rule = createRule({
85106
}
86107

87108
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier, composite: string) => {
109+
if (whitelist.includes(node.name)) return
88110
context.report({
89111
node,
90112
messageId: 'composite',

plugin/src/rules/prefer-longhand-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,31 @@ const rule: Rule = createRule({
1818
},
1919
type: 'suggestion',
2020
hasSuggestions: true,
21-
schema: [],
21+
schema: [
22+
{
23+
type: 'object',
24+
properties: {
25+
whitelist: {
26+
type: 'array',
27+
items: {
28+
type: 'string',
29+
minLength: 0,
30+
},
31+
uniqueItems: true,
32+
},
33+
},
34+
additionalProperties: false,
35+
},
36+
],
2237
},
23-
defaultOptions: [],
38+
defaultOptions: [
39+
{
40+
whitelist: [],
41+
},
42+
],
2443
create(context) {
44+
const whitelist: string[] = context.options[0]?.whitelist ?? []
45+
2546
// Cache for resolved longhand properties
2647
const longhandCache = new Map<string, string | undefined>()
2748

@@ -66,6 +87,7 @@ const rule: Rule = createRule({
6687
}
6788

6889
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier) => {
90+
if (whitelist.includes(node.name)) return
6991
const longhand = getLonghand(node.name)
7092
if (!longhand || longhand === node.name) return
7193

plugin/src/rules/prefer-shorthand-properties.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,31 @@ const rule: Rule = createRule({
1818
},
1919
type: 'suggestion',
2020
hasSuggestions: true,
21-
schema: [],
21+
schema: [
22+
{
23+
type: 'object',
24+
properties: {
25+
whitelist: {
26+
type: 'array',
27+
items: {
28+
type: 'string',
29+
minLength: 0,
30+
},
31+
uniqueItems: true,
32+
},
33+
},
34+
additionalProperties: false,
35+
},
36+
],
2237
},
23-
defaultOptions: [],
38+
defaultOptions: [
39+
{
40+
whitelist: [],
41+
},
42+
],
2443
create(context) {
44+
const whitelist: string[] = context.options[0]?.whitelist ?? []
45+
2546
// Cache for resolved longhand properties
2647
const longhandCache = new Map<string, string | undefined>()
2748

@@ -78,6 +99,7 @@ const rule: Rule = createRule({
7899
}
79100

80101
const sendReport = (node: TSESTree.Identifier | TSESTree.JSXIdentifier) => {
102+
if (whitelist.includes(node.name)) return
81103
const longhand = getLonghand(node.name)
82104
if (longhand) return // If it's already shorthand, no need to report
83105

sandbox/v9/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default tseslint.config({
3636
...panda.configs.recommended.rules,
3737
'@pandacss/no-margin-properties': 'warn',
3838
'@pandacss/no-physical-properties': 'error',
39-
'@pandacss/no-hardcoded-color': ['error', { noOpacity: true }],
39+
'@pandacss/no-hardcoded-color': ['error', { noOpacity: true, whitelist: ['inherit'] }],
4040
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
4141
},
4242
})

sandbox/v9/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function App() {
3535
margin: '4',
3636
pt: token('sizes.4'),
3737
paddingBlockEnd: ['4', pbe],
38+
borderColor: 'inherit',
3839
})
3940

4041
const color = 'red'

0 commit comments

Comments
 (0)