eslint-config-acme 1.0.0 → 1.2.0
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/README.md +78 -34
- package/index.js +7 -2
- package/lib/base.js +33 -0
- package/package.json +13 -10
- package/lib/prettier.js +0 -9
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ The goal of this configuration is to get code linting and formatting up and runn
|
|
|
18
18
|
|
|
19
19
|
To install the package, run:
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```shell
|
|
22
22
|
$ npm install -D eslint-config-acme
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -27,16 +27,19 @@ This will install the shared config, as well as its peer dependencies:
|
|
|
27
27
|
- eslint
|
|
28
28
|
- eslint-config-airbnb
|
|
29
29
|
- eslint-config-prettier
|
|
30
|
+
- eslint-import-resolver-alias
|
|
30
31
|
- eslint-plugin-import
|
|
31
32
|
- eslint-plugin-jsx-a11y
|
|
32
33
|
- eslint-plugin-prettier
|
|
33
34
|
- eslint-plugin-react
|
|
34
35
|
- eslint-plugin-react-hooks
|
|
36
|
+
- eslint-plugin-simple-import-sort
|
|
35
37
|
- prettier
|
|
38
|
+
- prettier-plugin-tailwindcss
|
|
36
39
|
|
|
37
|
-
**NOTE:** if you are on
|
|
40
|
+
**NOTE:** if you are on NPM <7, you will need to install these manually:
|
|
38
41
|
|
|
39
|
-
```
|
|
42
|
+
```shell
|
|
40
43
|
$ npx install-peerdeps -D eslint-config-acme
|
|
41
44
|
```
|
|
42
45
|
|
|
@@ -44,7 +47,7 @@ $ npx install-peerdeps -D eslint-config-acme
|
|
|
44
47
|
|
|
45
48
|
To start using this shared config, add `eslint-config-acme` (or just `acme`) to either your `package.json`:
|
|
46
49
|
|
|
47
|
-
```
|
|
50
|
+
```jsx
|
|
48
51
|
// package.json
|
|
49
52
|
{
|
|
50
53
|
"eslintConfig": {
|
|
@@ -55,60 +58,103 @@ To start using this shared config, add `eslint-config-acme` (or just `acme`) to
|
|
|
55
58
|
|
|
56
59
|
or the `.eslintrc` file:
|
|
57
60
|
|
|
58
|
-
```
|
|
61
|
+
```jsx
|
|
59
62
|
// .eslintrc
|
|
60
63
|
{
|
|
61
64
|
"extends": ["acme"]
|
|
62
65
|
}
|
|
63
66
|
```
|
|
64
67
|
|
|
65
|
-
##
|
|
68
|
+
## Import Alias
|
|
66
69
|
|
|
67
|
-
This config
|
|
70
|
+
This config provides a default import alias resolver for `eslint-plugin-import` to support shorthand imports of local modules:
|
|
68
71
|
|
|
69
72
|
```json
|
|
70
73
|
{
|
|
71
|
-
"
|
|
72
|
-
|
|
74
|
+
"import/resolver": {
|
|
75
|
+
"alias": {
|
|
76
|
+
"map": [["@", "./src"]],
|
|
77
|
+
"extensions": [".js", ".jsx"]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
```
|
|
75
82
|
|
|
76
|
-
|
|
83
|
+
This will allow you to write imports like this anywhere in your code:
|
|
77
84
|
|
|
78
|
-
```
|
|
85
|
+
```jsx
|
|
86
|
+
import Foo from '@/components/foo';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
instead of relative paths:
|
|
90
|
+
|
|
91
|
+
```jsx
|
|
92
|
+
import Foo from '../../components/foo';
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
when using [absolute imports and module path aliases](https://nextjs.org/docs/advanced-features/module-path-aliases) in **Next.js**.
|
|
96
|
+
|
|
97
|
+
This can also be overriden in your local `.eslintrc` file, if needed:
|
|
98
|
+
|
|
99
|
+
```jsx
|
|
100
|
+
// .eslintrc
|
|
101
|
+
{
|
|
102
|
+
"extends": ["acme"],
|
|
103
|
+
"settings": {
|
|
104
|
+
"import/resolver": {
|
|
105
|
+
"alias": {
|
|
106
|
+
"map": [["@", "./lib"]],
|
|
107
|
+
"extensions": [".js"]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Prettier
|
|
115
|
+
|
|
116
|
+
This config supports Prettier integration out of the box. Rules that may conflict with ESLint are disabled via recommended configuration in [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier).
|
|
117
|
+
|
|
118
|
+
If you wish to override any [Prettier options](https://prettier.io/docs/en/options.html), you can do so by specifying them under `prettier/prettier` rule in your ESLint config file. For example:
|
|
119
|
+
|
|
120
|
+
```jsx
|
|
79
121
|
// .eslintrc
|
|
80
122
|
{
|
|
81
|
-
"extends": "@acme",
|
|
123
|
+
"extends": ["@acme"],
|
|
82
124
|
"rules": {
|
|
83
125
|
"prettier/prettier": [
|
|
84
126
|
"error",
|
|
85
127
|
{
|
|
86
|
-
"printWidth":
|
|
128
|
+
"printWidth": 90
|
|
87
129
|
}
|
|
88
130
|
]
|
|
89
131
|
}
|
|
90
132
|
}
|
|
91
133
|
```
|
|
92
134
|
|
|
135
|
+
Make sure that these rules match the options specified in your `.prettierrc` file.
|
|
136
|
+
|
|
93
137
|
## Adding Scripts
|
|
94
138
|
|
|
95
139
|
Add the following to your `package.json` file to define a script that will lint all known files and output the results:
|
|
96
140
|
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
141
|
+
```jsx
|
|
142
|
+
// package.json
|
|
143
|
+
{
|
|
144
|
+
"scripts": {
|
|
145
|
+
"lint": "eslint --ignore-path .gitignore ."
|
|
146
|
+
}
|
|
102
147
|
}
|
|
103
148
|
```
|
|
104
149
|
|
|
105
|
-
To
|
|
150
|
+
To fix all automatically-fixable issues, you can add the following script to your `package.json` as well (in addition to above):
|
|
106
151
|
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
"
|
|
111
|
-
|
|
152
|
+
```jsx
|
|
153
|
+
// package.json
|
|
154
|
+
{
|
|
155
|
+
"scripts": {
|
|
156
|
+
"lint:fix": "eslint --ignore-path .gitignore --fix ."
|
|
157
|
+
}
|
|
112
158
|
}
|
|
113
159
|
```
|
|
114
160
|
|
|
@@ -120,18 +166,16 @@ There is a [known issue](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/is
|
|
|
120
166
|
|
|
121
167
|
Because of this, the [standard usage](https://nextjs.org/docs/api-reference/next/link) of Next.js `<Link>` component will result in an error for the `jsx-a11y/anchor-is-valid` rule. Until the Next.js API can be updated to a more standard pattern, `eslint-config-acme` overrides this rule as suggested in [this issue](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/402#issuecomment-368305051):
|
|
122
168
|
|
|
123
|
-
```
|
|
169
|
+
```json
|
|
124
170
|
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
'error',
|
|
171
|
+
"jsx-a11y/anchor-is-valid": [
|
|
172
|
+
"error",
|
|
128
173
|
{
|
|
129
|
-
components: [
|
|
130
|
-
specialLink: [
|
|
131
|
-
aspects: [
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
// ...
|
|
174
|
+
"components": ["Link"],
|
|
175
|
+
"specialLink": ["hrefLeft", "hrefRight"],
|
|
176
|
+
"aspects": ["invalidHref", "preferButton"]
|
|
177
|
+
}
|
|
178
|
+
]
|
|
135
179
|
}
|
|
136
180
|
```
|
|
137
181
|
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const base = require('./lib/base.js');
|
|
2
2
|
const next = require('./lib/next.js');
|
|
3
3
|
const react = require('./lib/react.js');
|
|
4
|
-
const prettier = require('./lib/prettier.js');
|
|
5
4
|
|
|
6
5
|
module.exports = {
|
|
7
6
|
extends: ['airbnb', 'airbnb/hooks', 'plugin:prettier/recommended'],
|
|
@@ -19,16 +18,22 @@ module.exports = {
|
|
|
19
18
|
jsx: true,
|
|
20
19
|
},
|
|
21
20
|
},
|
|
21
|
+
plugins: ['simple-import-sort', 'import'],
|
|
22
22
|
rules: {
|
|
23
23
|
...base,
|
|
24
24
|
...next,
|
|
25
25
|
...react,
|
|
26
|
-
...prettier,
|
|
27
26
|
},
|
|
28
27
|
settings: {
|
|
29
28
|
react: {
|
|
30
29
|
// Tells eslint-plugin-react to automatically detect the version of React to use
|
|
31
30
|
version: 'detect',
|
|
32
31
|
},
|
|
32
|
+
'import/resolver': {
|
|
33
|
+
alias: {
|
|
34
|
+
map: [['@', './src']],
|
|
35
|
+
extensions: ['.js', '.jsx'],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
33
38
|
},
|
|
34
39
|
};
|
package/lib/base.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
'import/no-extraneous-dependencies': [
|
|
3
|
+
'error',
|
|
4
|
+
{
|
|
5
|
+
devDependencies: true,
|
|
6
|
+
},
|
|
7
|
+
],
|
|
2
8
|
'import/prefer-default-export': 0,
|
|
9
|
+
'import/first': 'error',
|
|
10
|
+
'import/newline-after-import': 'error',
|
|
11
|
+
'import/no-duplicates': 'error',
|
|
12
|
+
'simple-import-sort/imports': [
|
|
13
|
+
'error',
|
|
14
|
+
{
|
|
15
|
+
groups: [
|
|
16
|
+
// Node.js builtins
|
|
17
|
+
[
|
|
18
|
+
'^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)',
|
|
19
|
+
],
|
|
20
|
+
// Packages. `react` related packages come first
|
|
21
|
+
['^react', '^@?\\w'],
|
|
22
|
+
// Side effect imports
|
|
23
|
+
['^\\u0000'],
|
|
24
|
+
// Internal packages
|
|
25
|
+
['^(src|internals)(/.*|$)'],
|
|
26
|
+
// Parent imports. Put `..` last
|
|
27
|
+
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
|
|
28
|
+
// Other relative imports. Put same-folder imports and `.` last
|
|
29
|
+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
|
|
30
|
+
// Style imports
|
|
31
|
+
['^.+\\.s?css$'],
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
'simple-import-sort/exports': 'error',
|
|
3
36
|
'no-console': 'warn',
|
|
4
37
|
'no-nested-ternary': 0,
|
|
5
38
|
'no-underscore-dangle': 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-acme",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "ESLint + Prettier config for React (Next.js)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
"lint:fix": "eslint --fix"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"eslint": "^
|
|
18
|
-
"eslint-config-airbnb": "^
|
|
19
|
-
"eslint-config-prettier": "^8.
|
|
20
|
-
"eslint-
|
|
21
|
-
"eslint-plugin-
|
|
22
|
-
"eslint-plugin-
|
|
23
|
-
"eslint-plugin-
|
|
24
|
-
"eslint-plugin-react
|
|
25
|
-
"
|
|
17
|
+
"eslint": "^8.8.0",
|
|
18
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
19
|
+
"eslint-config-prettier": "^8.3.0",
|
|
20
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
21
|
+
"eslint-plugin-import": "^2.25.4",
|
|
22
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
23
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
24
|
+
"eslint-plugin-react": "^7.28.0",
|
|
25
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
26
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
27
|
+
"prettier": "^2.5.1",
|
|
28
|
+
"prettier-plugin-tailwindcss": "^0.1.4"
|
|
26
29
|
},
|
|
27
30
|
"keywords": [
|
|
28
31
|
"config",
|