@will-stone/eslint-config 0.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @will-stone/eslint-config
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 40e33d5: Initial release.
@@ -0,0 +1,151 @@
1
+ import fs from 'node:fs'
2
+
3
+ import importPlugin from 'eslint-plugin-import'
4
+ import jestPlugin from 'eslint-plugin-jest'
5
+ import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'
6
+ import nPlugin from 'eslint-plugin-n'
7
+ import prettierPlugin from 'eslint-plugin-prettier'
8
+ import reactPlugin from 'eslint-plugin-react'
9
+ import reactHooksPlugin from 'eslint-plugin-react-hooks'
10
+ import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort'
11
+ import switchCasePlugin from 'eslint-plugin-switch-case'
12
+ import unicornPlugin from 'eslint-plugin-unicorn'
13
+ import globals from 'globals'
14
+ import { globbySync } from 'globby'
15
+ import { loadJsonFileSync } from 'load-json-file'
16
+
17
+ import builtInRules from './rules/built-in.js'
18
+ import importRules from './rules/import.js'
19
+ import jestRules from './rules/jest.js'
20
+ import jestTsRules from './rules/jest-ts.js'
21
+ import jsxA11yRules from './rules/jsx-a11y.js'
22
+ import nodeRules from './rules/node.js'
23
+ import prettierRules from './rules/prettier.js'
24
+ import reactRules from './rules/react.js'
25
+ import switchCaseRules from './rules/switch-case.js'
26
+ import tsRules from './rules/typescript.js'
27
+ import unicornRules from './rules/unicorn.js'
28
+
29
+ let testingFramework = null
30
+ let isNodeEngine = false
31
+ let isPrettier = false
32
+
33
+ // In a monorepo environment with one eslint instance at the root of the project,
34
+ // we must traverse every child package.json to find out if certain dependencies
35
+ // are included, so that we know which plugins and rules to include.
36
+ const allPackageJsonPaths = globbySync([
37
+ '**/package.json',
38
+ // Could use the `gitIgnore` option but the negative pattern is about 8 times faster.
39
+ // https://github.com/sindresorhus/globby/issues/50
40
+ '!**/node_modules',
41
+ ])
42
+
43
+ for (const packageJsonPath of allPackageJsonPaths) {
44
+ const packageJson = loadJsonFileSync(packageJsonPath)
45
+
46
+ if (
47
+ !testingFramework &&
48
+ Boolean(packageJson.dependencies?.jest || packageJson.devDependencies?.jest)
49
+ ) {
50
+ testingFramework = 'jest'
51
+ }
52
+
53
+ if (!isNodeEngine && Boolean(packageJson.engines?.node)) {
54
+ isNodeEngine = true
55
+ }
56
+
57
+ if (
58
+ !isPrettier &&
59
+ Boolean(
60
+ packageJson.dependencies?.prettier ||
61
+ packageJson.devDependencies?.prettier,
62
+ )
63
+ ) {
64
+ isPrettier = true
65
+ }
66
+ }
67
+
68
+ const isNode =
69
+ isNodeEngine || fs.existsSync('.nvmrc') || fs.existsSync('.node-version')
70
+
71
+ export default [
72
+ // Global
73
+ {
74
+ settings: {
75
+ react: {
76
+ version: 'detect',
77
+ },
78
+ },
79
+ },
80
+
81
+ // Base
82
+ {
83
+ files: ['**/*.{js,cjs,mjs,jsx,ts,tsx}'],
84
+ languageOptions: {
85
+ globals: isNode && globals.node,
86
+ },
87
+ plugins: {
88
+ 'import': importPlugin,
89
+ 'simple-import-sort': simpleImportSortPlugin,
90
+ 'switch-case': switchCasePlugin,
91
+ 'unicorn': unicornPlugin,
92
+ ...(isNode && { n: nPlugin }),
93
+ ...(isPrettier && { prettier: prettierPlugin }),
94
+ },
95
+ rules: {
96
+ ...builtInRules,
97
+ ...importRules,
98
+ ...switchCaseRules,
99
+ ...unicornRules,
100
+ ...(isNode && nodeRules),
101
+ ...(isPrettier && prettierRules),
102
+ },
103
+ },
104
+
105
+ // TS
106
+ {
107
+ files: ['**/*.{ts,tsx}'],
108
+ languageOptions: {
109
+ parser: '@typescript-eslint/parser',
110
+ },
111
+ rules: tsRules,
112
+ },
113
+
114
+ // JSX files (React)
115
+ {
116
+ files: ['**/*.{jsx,tsx}'],
117
+ languageOptions: {
118
+ globals: globals.browser,
119
+ parserOptions: {
120
+ ecmaFeatures: {
121
+ jsx: true,
122
+ },
123
+ },
124
+ },
125
+ plugins: {
126
+ 'jsx-a11y': jsxA11yPlugin,
127
+ 'react': reactPlugin,
128
+ 'react-hooks': reactHooksPlugin,
129
+ },
130
+ rules: {
131
+ ...jsxA11yRules,
132
+ ...reactRules,
133
+ },
134
+ },
135
+
136
+ // Jest
137
+ {
138
+ files: ['**/*.{spec,test}.{js,cjs,mjs,jsx,ts,tsx}'],
139
+ languageOptions: {
140
+ globals: testingFramework === 'jest' && globals.jest,
141
+ },
142
+ plugins: testingFramework === 'jest' && {
143
+ jest: jestPlugin,
144
+ },
145
+ rules: testingFramework === 'jest' && jestRules,
146
+ },
147
+ {
148
+ files: ['**/*.{spec,test}.{ts,tsx}'],
149
+ rules: testingFramework === 'jest' && jestTsRules,
150
+ },
151
+ ]
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@will-stone/eslint-config",
3
+ "version": "0.0.1",
4
+ "description": "Will Stone's ESLint config, using the Flat Config style.",
5
+ "keywords": [
6
+ "ESLint"
7
+ ],
8
+ "homepage": "https://github.com/will-stone/dx#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/will-stone/dx/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/will-stone/dx.git"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Will Stone",
18
+ "type": "module",
19
+ "main": "eslint-config.js",
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1"
22
+ },
23
+ "dependencies": {
24
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
25
+ "@typescript-eslint/parser": "^6.7.0",
26
+ "confusing-browser-globals": "^1.0.11",
27
+ "eslint-plugin-import": "^2.28.1",
28
+ "eslint-plugin-jest": "^27.4.0",
29
+ "eslint-plugin-jsx-a11y": "^6.7.1",
30
+ "eslint-plugin-n": "^16.1.0",
31
+ "eslint-plugin-prettier": "^5.0.0",
32
+ "eslint-plugin-react": "^7.33.2",
33
+ "eslint-plugin-react-hooks": "^4.6.0",
34
+ "eslint-plugin-simple-import-sort": "^10.0.0",
35
+ "eslint-plugin-switch-case": "^1.1.2",
36
+ "eslint-plugin-unicorn": "^48.0.1",
37
+ "globals": "^13.21.0",
38
+ "globby": "^13.2.2",
39
+ "load-json-file": "^7.0.1"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ }
44
+ }