@coko/lint 3.0.0-alpha.3 → 3.0.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/eslint.bak.js CHANGED
@@ -1,106 +1,106 @@
1
- module.exports = {
2
- parser: '@babel/eslint-parser',
3
- parserOptions: {
4
- requireConfigFile: false,
5
- babelOptions: {
6
- presets: ['@babel/preset-react'],
7
- },
8
- },
9
- overrides: [
10
- {
11
- files: ['*.jsx'],
12
- },
13
- ],
14
- env: {
15
- browser: true,
16
- es6: true,
17
- jest: true,
18
- node: true,
19
- },
20
- extends: [
21
- 'airbnb',
22
- 'standard',
23
- 'standard-react',
24
- 'plugin:jest/recommended',
25
- 'plugin:cypress/recommended',
26
- 'prettier',
27
- ],
28
- plugins: ['jest'],
29
- ignorePatterns: [
30
- '_build',
31
- 'dist',
32
- '!.storybook',
33
- '!.commitlintrc.js',
34
- '!.cz-config.js',
35
- '!.eslintrc.js',
36
- '!.jest.config.js',
37
- '!.lintstagedrc.js',
38
- '!.prettierrc.js',
39
- '!.stylelintrc.js',
40
- '**/node_modules',
41
- ],
42
- rules: {
43
- 'arrow-body-style': 0,
44
- 'import/no-extraneous-dependencies': [
45
- 'error',
46
- {
47
- devDependencies: [
48
- // storybook
49
- '.storybook/*',
50
- '**/stories/**/*.js',
1
+ // module.exports = {
2
+ // parser: '@babel/eslint-parser',
3
+ // parserOptions: {
4
+ // requireConfigFile: false,
5
+ // babelOptions: {
6
+ // presets: ['@babel/preset-react'],
7
+ // },
8
+ // },
9
+ // overrides: [
10
+ // {
11
+ // files: ['*.jsx'],
12
+ // },
13
+ // ],
14
+ // env: {
15
+ // browser: true,
16
+ // es6: true,
17
+ // jest: true,
18
+ // node: true,
19
+ // },
20
+ // extends: [
21
+ // 'airbnb',
22
+ // 'standard',
23
+ // 'standard-react',
24
+ // 'plugin:jest/recommended',
25
+ // 'plugin:cypress/recommended',
26
+ // 'prettier',
27
+ // ],
28
+ // plugins: ['jest'],
29
+ // ignorePatterns: [
30
+ // '_build',
31
+ // 'dist',
32
+ // '!.storybook',
33
+ // '!.commitlintrc.js',
34
+ // '!.cz-config.js',
35
+ // '!.eslintrc.js',
36
+ // '!.jest.config.js',
37
+ // '!.lintstagedrc.js',
38
+ // '!.prettierrc.js',
39
+ // '!.stylelintrc.js',
40
+ // '**/node_modules',
41
+ // ],
42
+ // rules: {
43
+ // 'arrow-body-style': 0,
44
+ // 'import/no-extraneous-dependencies': [
45
+ // 'error',
46
+ // {
47
+ // devDependencies: [
48
+ // // storybook
49
+ // '.storybook/*',
50
+ // '**/stories/**/*.js',
51
51
 
52
- // tests
53
- 'cypress/**',
54
- '**/*.spec.js',
55
- '**/*.test.js',
52
+ // // tests
53
+ // 'cypress/**',
54
+ // '**/*.spec.js',
55
+ // '**/*.test.js',
56
56
 
57
- // webpack
58
- 'webpack/**',
57
+ // // webpack
58
+ // 'webpack/**',
59
59
 
60
- // configs
61
- '.commitlintrc.js',
62
- '.cz-config.js',
63
- '.eslintrc.js',
64
- '.jest.config.js',
65
- '.lintstagedrc.js',
66
- '.prettierrc.js',
67
- '.stylelintrc.js',
60
+ // // configs
61
+ // '.commitlintrc.js',
62
+ // '.cz-config.js',
63
+ // '.eslintrc.js',
64
+ // '.jest.config.js',
65
+ // '.lintstagedrc.js',
66
+ // '.prettierrc.js',
67
+ // '.stylelintrc.js',
68
68
 
69
- // other
70
- 'dev/**',
71
- ],
72
- },
73
- ],
74
- 'jsx-a11y/anchor-is-valid': [
75
- 'error',
76
- {
77
- components: ['Link'],
78
- specialLink: ['to', 'hrefLeft', 'hrefRight'],
79
- aspects: ['noHref', 'invalidHref', 'preferButton'],
80
- },
81
- ],
82
- 'no-console': ['error', { allow: ['warn', 'error'] }],
83
- 'padding-line-between-statements': [
84
- 'error',
85
- { blankLine: 'always', prev: '*', next: 'block' },
86
- { blankLine: 'always', prev: 'block', next: '*' },
87
- { blankLine: 'always', prev: '*', next: 'block-like' },
88
- { blankLine: 'always', prev: 'block-like', next: '*' },
89
- { blankLine: 'always', prev: '*', next: 'multiline-const' },
90
- { blankLine: 'always', prev: 'multiline-const', next: '*' },
91
- ],
92
- // 'prettier/prettier': 'error',
93
- 'react/function-component-definition': [
94
- 2,
95
- { namedComponents: 'arrow-function' },
96
- ],
97
- 'react/jsx-filename-extension': [2, { extensions: ['.js'] }], // disallows .jsx files
98
- 'react/jsx-props-no-spreading': 0,
99
- 'react/jsx-sort-props': [1, { ignoreCase: true }],
100
- 'react/prop-types': [
101
- 2,
102
- { ignore: ['children', 'className', 'onClick', 'theme'] },
103
- ],
104
- // 'sort-keys': [1, 'asc', { caseSensitive: false }],
105
- },
106
- }
69
+ // // other
70
+ // 'dev/**',
71
+ // ],
72
+ // },
73
+ // ],
74
+ // 'jsx-a11y/anchor-is-valid': [
75
+ // 'error',
76
+ // {
77
+ // components: ['Link'],
78
+ // specialLink: ['to', 'hrefLeft', 'hrefRight'],
79
+ // aspects: ['noHref', 'invalidHref', 'preferButton'],
80
+ // },
81
+ // ],
82
+ // 'no-console': ['error', { allow: ['warn', 'error'] }],
83
+ // 'padding-line-between-statements': [
84
+ // 'error',
85
+ // { blankLine: 'always', prev: '*', next: 'block' },
86
+ // { blankLine: 'always', prev: 'block', next: '*' },
87
+ // { blankLine: 'always', prev: '*', next: 'block-like' },
88
+ // { blankLine: 'always', prev: 'block-like', next: '*' },
89
+ // { blankLine: 'always', prev: '*', next: 'multiline-const' },
90
+ // { blankLine: 'always', prev: 'multiline-const', next: '*' },
91
+ // ],
92
+ // // 'prettier/prettier': 'error',
93
+ // 'react/function-component-definition': [
94
+ // 2,
95
+ // { namedComponents: 'arrow-function' },
96
+ // ],
97
+ // 'react/jsx-filename-extension': [2, { extensions: ['.js'] }], // disallows .jsx files
98
+ // 'react/jsx-props-no-spreading': 0,
99
+ // 'react/jsx-sort-props': [1, { ignoreCase: true }],
100
+ // 'react/prop-types': [
101
+ // 2,
102
+ // { ignore: ['children', 'className', 'onClick', 'theme'] },
103
+ // ],
104
+ // // 'sort-keys': [1, 'asc', { caseSensitive: false }],
105
+ // },
106
+ // }
package/src/eslint.mjs CHANGED
@@ -1,49 +1,17 @@
1
- // import path from 'path'
2
-
3
1
  import { defineConfig, globalIgnores } from 'eslint/config'
4
2
  import js from '@eslint/js'
5
- // import { FlatCompat } from '@eslint/eslintrc'
6
-
7
3
  import globals from 'globals'
8
4
  import tseslint from 'typescript-eslint'
9
- // import babelParser from '@babel/eslint-parser'
10
-
11
- import nodePlugin from 'eslint-plugin-n'
12
5
  import importPlugin from 'eslint-plugin-import'
13
- // import jest from 'eslint-plugin-jest'
14
- // import cypressPlugin from 'eslint-plugin-cypress'
15
-
16
- // const __filename = fileURLToPath(import.meta.url)
17
- // const __dirname = path.dirname(__filename)
18
-
19
- // const compat = new FlatCompat({
20
- // // baseDirectory: __dirname,
21
- // resolvePluginsRelativeTo: import.meta.url,
22
- // // recommendedConfig: js.configs.recommended,
23
- // // allConfig: js.configs.all,
24
- // })
25
-
26
- /**
27
- * TO DO
28
- *
29
- * explicit rules from old config
30
- * jest
31
- * cypress
32
- *
33
- * => client
34
- * no console
35
- * jsx a11y
36
- * airbnb react
37
- * react recommended
38
- * react hooks
39
- * confusing-browser-globals
40
- *
41
- * => drop dependencies
42
- * airbnb
43
- * @eslint/eslintrc (if not using flat compat)
44
- * babel eslint parser
45
- *
46
- */
6
+ import workspaces from 'eslint-plugin-workspaces'
7
+ import pluginPromise from 'eslint-plugin-promise'
8
+ import nodePlugin from 'eslint-plugin-n'
9
+ import pluginCypress from 'eslint-plugin-cypress'
10
+ import vitest from '@vitest/eslint-plugin'
11
+ import react from 'eslint-plugin-react'
12
+ import reactHooks from 'eslint-plugin-react-hooks'
13
+ import jsxA11y from 'eslint-plugin-jsx-a11y'
14
+ import confusingBrowserGlobals from 'confusing-browser-globals'
47
15
 
48
16
  const commonRules = {
49
17
  'array-callback-return': 'error',
@@ -87,7 +55,6 @@ const commonRules = {
87
55
  'no-template-curly-in-string': 'warn',
88
56
  'no-throw-literal': 'error',
89
57
  'no-undef-init': 'warn',
90
- 'no-undefined': 'error',
91
58
  'no-unneeded-ternary': ['error', { defaultAssignment: false }],
92
59
  'no-unused-expressions': 'error',
93
60
  'no-useless-computed-key': 'error',
@@ -109,7 +76,9 @@ const commonRules = {
109
76
  'ignorePackages',
110
77
  {
111
78
  js: 'never',
79
+ jsx: 'never',
112
80
  ts: 'never',
81
+ tsx: 'never',
113
82
  },
114
83
  ],
115
84
  'import/no-absolute-path': 'error',
@@ -120,25 +89,33 @@ const commonRules = {
120
89
  devDependencies: [
121
90
  // storybook
122
91
  '.storybook/*',
123
- '**/stories/**/*.js',
92
+ '**/stories/**/*',
124
93
 
125
94
  // tests
126
95
  'cypress/**',
127
96
  '**/*.spec.js',
97
+ '**/*.spec.ts',
128
98
  '**/*.test.js',
99
+ '**/*.test.ts',
129
100
  '**/__tests__/**/*',
130
-
131
- // webpack
132
- 'webpack/**',
101
+ '**/vitest.config.*',
133
102
 
134
103
  // configs
135
- '.commitlintrc.js',
136
104
  '.cz-config.js',
137
- '.jest.config.js',
105
+ '.cz-config.ts',
106
+ '.cz-config.mjs',
107
+ '.cz-config.cjs',
138
108
  '.lintstagedrc.js',
109
+ '.lintstagedrc.ts',
110
+ '.lintstagedrc.mjs',
139
111
  '.prettierrc.js',
112
+ '.prettierrc.ts',
113
+ '.prettierrc.mjs',
140
114
  '.stylelintrc.js',
115
+ '.stylelintrc.ts',
116
+ '.stylelintrc.mjs',
141
117
  'eslint.config.js',
118
+ 'eslint.config.ts',
142
119
  'eslint.config.mjs',
143
120
 
144
121
  // other
@@ -151,9 +128,75 @@ const commonRules = {
151
128
  'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }],
152
129
  }
153
130
 
131
+ const workspacesConfig = {
132
+ plugins: { workspaces },
133
+ rules: {
134
+ 'workspaces/no-relative-imports': 'error',
135
+ 'workspaces/require-dependency': 'warn',
136
+ },
137
+ }
138
+
139
+ const typescriptConfig = {
140
+ files: ['**/*.{ts,tsx}'],
141
+ languageOptions: {
142
+ parser: tseslint.parser,
143
+ },
144
+ plugins: {
145
+ '@typescript-eslint': tseslint.plugin,
146
+ },
147
+ rules: {
148
+ ...tseslint.configs.recommended.rules,
149
+ '@typescript-eslint/explicit-function-return-type': 'error',
150
+
151
+ 'no-redeclare': 'off',
152
+ '@typescript-eslint/no-redeclare': 'error',
153
+
154
+ 'no-unused-vars': 'off',
155
+ '@typescript-eslint/no-unused-vars': [
156
+ 'error',
157
+ {
158
+ argsIgnorePattern: '^_',
159
+ varsIgnorePattern: '^_',
160
+ caughtErrorsIgnorePattern: '^_',
161
+ },
162
+ ],
163
+ },
164
+ }
165
+
166
+ const viteConfig = {
167
+ files: ['**/__tests__/**/*.test.ts'],
168
+ plugins: {
169
+ vitest,
170
+ },
171
+ // settings: {
172
+ // vitest: {
173
+ // typecheck: true,
174
+ // },
175
+ // },
176
+ rules: {
177
+ ...vitest.configs.recommended.rules,
178
+ 'vitest/no-focused-tests': ['error', { fixable: false }],
179
+ },
180
+ }
181
+
182
+ const globalIgnoreList = [
183
+ '**/_build',
184
+ '**/dist',
185
+ '**/docs',
186
+ '!**/.storybook',
187
+ '!**/.cz-config.js',
188
+ '!**/.cz-config.cjs',
189
+ '!**/.lintstagedrc.js',
190
+ '!**/.prettierrc.js',
191
+ '!**/.stylelintrc.js',
192
+ '**/node_modules',
193
+ ]
194
+
154
195
  const server = [
155
196
  js.configs.recommended,
156
197
  importPlugin.flatConfigs.recommended,
198
+ pluginPromise.configs['flat/recommended'],
199
+ workspacesConfig,
157
200
 
158
201
  {
159
202
  files: ['**/*.{js,mjs,ts}'],
@@ -175,6 +218,7 @@ const server = [
175
218
  rules: {
176
219
  ...commonRules,
177
220
  'no-console': 'error',
221
+ // 'n/no-process-exit': 'off',
178
222
  'import/no-unresolved': ['error', { commonjs: true }],
179
223
  },
180
224
  },
@@ -189,28 +233,6 @@ const server = [
189
233
  },
190
234
  },
191
235
 
192
- {
193
- files: ['**/*.mjs', '**/*.ts'],
194
- languageOptions: {
195
- sourceType: 'module',
196
- },
197
- rules: {
198
- 'no-restricted-globals': [
199
- 'error',
200
- {
201
- name: '__dirname',
202
- message:
203
- 'Do not use __dirname; use import.meta.url or process.cwd().',
204
- },
205
- {
206
- name: '__filename',
207
- message:
208
- 'Do not use __filename in ES modules or TypeScript; use import.meta.url or path.resolve() instead.',
209
- },
210
- ],
211
- },
212
- },
213
-
214
236
  {
215
237
  files: ['**/*.mjs'],
216
238
  rules: {
@@ -218,33 +240,76 @@ const server = [
218
240
  },
219
241
  },
220
242
 
243
+ typescriptConfig,
244
+ viteConfig,
245
+ globalIgnores(globalIgnoreList),
246
+ ]
247
+
248
+ const client = [
249
+ js.configs.recommended,
250
+ importPlugin.flatConfigs.recommended,
251
+ pluginPromise.configs['flat/recommended'],
252
+ workspacesConfig,
253
+ react.configs.flat.recommended,
254
+ react.configs.flat['jsx-runtime'],
255
+ reactHooks.configs.flat.recommended,
256
+ jsxA11y.flatConfigs.recommended,
257
+
221
258
  {
222
- files: ['**/*.ts'],
259
+ files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
223
260
  languageOptions: {
224
- parser: tseslint.parser,
261
+ globals: {
262
+ ...globals.browser,
263
+ process: 'readonly',
264
+ },
265
+ ecmaVersion: 'latest',
266
+ parserOptions: {
267
+ ecmaFeatures: {
268
+ jsx: true,
269
+ },
270
+ },
225
271
  },
226
- plugins: {
227
- '@typescript-eslint': tseslint.plugin,
272
+ settings: {
273
+ 'import/resolver': {
274
+ typescript: {
275
+ alwaysTryTypes: true,
276
+ },
277
+ },
278
+ react: {
279
+ version: 'detect',
280
+ },
228
281
  },
229
282
  rules: {
230
- ...tseslint.configs.recommended.rules,
231
- '@typescript-eslint/explicit-function-return-type': 'error',
283
+ ...commonRules,
284
+ 'no-console': ['error', { allow: ['warn', 'error'] }],
285
+ 'import/no-unresolved': 'error',
286
+ 'react/jsx-sort-props': [1, { ignoreCase: true }],
287
+ 'no-restricted-globals': ['error'].concat(confusingBrowserGlobals),
232
288
  },
233
289
  },
234
290
 
235
- globalIgnores([
236
- '**/_build',
237
- '**/dist',
238
- '**/docs',
239
- '!**/.storybook',
240
- '!**/.commitlintrc.js',
241
- '!**/.cz-config.js',
242
- '!**/.jest.config.js',
243
- '!**/.lintstagedrc.js',
244
- '!**/.prettierrc.js',
245
- '!**/.stylelintrc.js',
246
- '**/node_modules',
247
- ]),
291
+ {
292
+ files: ['**/*.cjs'],
293
+ languageOptions: { sourceType: 'commonjs' },
294
+ },
295
+
296
+ typescriptConfig,
297
+ viteConfig,
298
+ globalIgnores(globalIgnoreList),
248
299
  ]
249
300
 
250
- export { defineConfig as defineEslintConfig, server as serverEslintConfig }
301
+ const root = [
302
+ ...server,
303
+
304
+ {
305
+ files: ['cypress/**/*.{js,mjs,ts}'],
306
+ extends: [pluginCypress.configs.recommended],
307
+ },
308
+ ]
309
+
310
+ export {
311
+ defineConfig as defineEslintConfig,
312
+ server as serverEslintConfig,
313
+ client as clientEslintConfig,
314
+ root as rootEslintConfig,
315
+ }
package/src/index.mjs CHANGED
@@ -1,12 +1,22 @@
1
- import commitizen from './commitizen'
2
- import { defineEslintConfig, serverEslintConfig } from './eslint.mjs'
3
- import prettier from './prettier'
4
- import stylelint from './stylelint'
5
- import lintstaged from './lintstaged'
1
+ /* eslint-disable-next-line import/extensions */
2
+ import commitizen from './commitizen.js'
3
+
4
+ import {
5
+ defineEslintConfig,
6
+ serverEslintConfig,
7
+ clientEslintConfig,
8
+ rootEslintConfig,
9
+ } from './eslint.mjs'
10
+
11
+ import prettier from './prettier.mjs'
12
+ import stylelint from './stylelint.mjs'
13
+ import lintstaged from './lintstaged.mjs'
6
14
 
7
15
  export {
8
16
  defineEslintConfig,
9
17
  serverEslintConfig,
18
+ clientEslintConfig,
19
+ rootEslintConfig,
10
20
  stylelint,
11
21
  prettier,
12
22
  commitizen,
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  '*.js': ['eslint', 'stylelint'],
3
3
  '*.{js,graphql,json,yml,md,html}': ['prettier --check'],
4
4
  }
package/src/logger.mjs ADDED
@@ -0,0 +1,21 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import chalk from 'chalk'
4
+
5
+ const pre = chalk.cyan.underline('[coko lint]')
6
+ const primary = chalk.cyan
7
+ const error = chalk.red
8
+
9
+ const logger = {
10
+ error: str => {
11
+ console.log(error(`${pre} ${str}`))
12
+ },
13
+ info: str => {
14
+ console.log(primary(`${pre} ${str}`))
15
+ },
16
+ newLine: () => {
17
+ console.log('')
18
+ },
19
+ }
20
+
21
+ export default logger
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  arrowParens: 'avoid',
3
3
  semi: false,
4
4
  singleQuote: true,
@@ -0,0 +1,17 @@
1
+ export default {
2
+ extends: ['stylelint-config-standard'],
3
+ overrides: [
4
+ {
5
+ files: ['**/*.{js,jsx,mjs,mts,ts,tsx}'],
6
+ customSyntax: 'postcss-styled-syntax',
7
+ },
8
+ ],
9
+ rules: {
10
+ 'comment-empty-line-before': null,
11
+ 'declaration-empty-line-before': null,
12
+ 'declaration-block-no-duplicate-properties': true,
13
+ 'declaration-no-important': true,
14
+ 'no-descending-specificity': null,
15
+ 'no-empty-source': null,
16
+ },
17
+ }
@@ -1,26 +0,0 @@
1
- // const confusingBrowserGlobals = require('confusing-browser-globals')
2
-
3
- export default {
4
- rules: {
5
- // disallow specific globals
6
- 'no-restricted-globals': [
7
- 'error',
8
- {
9
- name: 'isFinite',
10
- message:
11
- 'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite',
12
- },
13
- {
14
- name: 'isNaN',
15
- message:
16
- 'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
17
- },
18
- ]
19
- .concat
20
- // confusingBrowserGlobals.map(g => ({
21
- // name: g,
22
- // message: `Use window.${g} instead. https://github.com/facebook/create-react-app/blob/HEAD/packages/confusing-browser-globals/README.md`,
23
- // })),
24
- (),
25
- },
26
- }