-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheslint.shared.mjs
More file actions
138 lines (126 loc) · 3.67 KB
/
Copy patheslint.shared.mjs
File metadata and controls
138 lines (126 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** @import { Linter } from 'eslint' */
import betterTailwindcss from 'eslint-plugin-better-tailwindcss';
import storybook from 'eslint-plugin-storybook';
import { globalIgnores } from 'eslint/config';
const ext = '{js,jsx,ts,tsx,cjs,cts,mjs,mts}';
const allFilePatterns = [`**/*.${ext}`];
const prodFilePatterns = [`src/**/*.${ext}`];
/** TS/JS source files that may contain Tailwind classes or Storybook config. */
const tsJsFilePatterns = ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'];
const devFilePatterns = [
/** configs & tooling */
`**/eslint.config.${ext}`,
`**/test-setup.${ext}`,
`**/jest.setup.${ext}`,
/** specific files pattern */
`**/*.stories.${ext}`,
`**/*.figma.${ext}`,
`**/*.test.${ext}`,
`**/*.spec.${ext}`,
/** specific folders considered as dev */
`apps/**/*.${ext}`,
];
const globalIgnorePatterns = [
'dist/**',
'**/dist',
'**/out-tsc',
'node_modules',
'**/storybook-static',
'**/vite.config.*.timestamp*',
'**/vitest.config.*.timestamp*',
];
export const definedGlobalIgnores = globalIgnores(globalIgnorePatterns);
/**
* Define rules for all js/ts files
* @param {Linter.Config} config
* @returns {Linter.Config}
*/
export const defineGlobalRules = (config) => ({
name: 'all-files-rules',
...config,
files: allFilePatterns,
ignores: globalIgnorePatterns,
});
/**
* Define rules for production js/ts files
* Production files should always be exposed in src/*
* @param {Linter.Config} config
* @returns {Linter.Config}
*/
export const defineProdRules = (config) => ({
name: 'production-files-only-rules',
...config,
files: [...prodFilePatterns, ...(config.files ?? [])],
ignores: [
...devFilePatterns,
...globalIgnorePatterns,
...(config.ignores ?? []),
],
});
/**
* Define rules for development js/ts files (tooling, tests, configs, etc.)
* @param {Linter.Config} config
* @returns {Linter.Config}
*/
export const defineDevRules = (config) => ({
name: 'development-files-only-rules',
...config,
files: [...devFilePatterns, ...(config.files ?? [])],
ignores: [
...globalIgnorePatterns,
...(config.ignores ?? []),
],
});
/**
* Storybook addon validation. Registers the Storybook plugin in scope so the
* `no-uninstalled-addons` rule resolves, checking declared addons against the
* given package.json.
* @param {{ packageJsonLocation: string }} options
* @returns {Linter.Config}
*/
export const defineStorybookAddons = ({ packageJsonLocation }) => ({
name: 'storybook-addons-rules',
files: tsJsFilePatterns,
plugins: { storybook },
rules: {
'storybook/no-uninstalled-addons': ['error', { packageJsonLocation }],
},
});
/**
* Better Tailwind CSS rules and settings for a project's class utilities.
* @param {{ entryPoint: string, tailwindConfig: string }} options
* @returns {Linter.Config}
*/
export const defineTailwindRules = ({ entryPoint, tailwindConfig }) => ({
name: 'better-tailwindcss-rules',
files: tsJsFilePatterns,
plugins: { 'better-tailwindcss': betterTailwindcss },
rules: {
...betterTailwindcss.configs['recommended-warn'].rules,
...betterTailwindcss.configs['recommended-error'].rules,
'better-tailwindcss/enforce-consistent-line-wrapping': 'off',
},
settings: {
'better-tailwindcss': {
callees: [
['cn', [{ match: 'strings' }]],
[
'cva',
[
{ match: 'strings' },
{
match: 'objectValues',
pathPattern: '^variants.*$',
},
{
match: 'objectValues',
pathPattern: '^compoundVariants\\[\\d+\\]\\.(?:className|class)$',
},
],
],
],
entryPoint,
tailwindConfig,
},
},
});