@bedrockio/eslint-plugin 1.1.2 → 1.1.3
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 +80 -16
- package/dist/cjs/mdx.js +1 -0
- package/dist/cjs/node-imports.js +12 -3
- package/dist/cjs/react.js +1 -0
- package/dist/cjs/webpack-imports.js +9 -10
- package/package.json +1 -1
- package/src/mdx.js +1 -0
- package/src/node-imports.js +9 -1
- package/src/react.js +1 -0
- package/src/webpack-imports.js +9 -8
package/README.md
CHANGED
|
@@ -1,31 +1,95 @@
|
|
|
1
1
|
# @bedrockio/eslint-plugin
|
|
2
2
|
|
|
3
|
-
Common ESLint plugin for Bedrock projects.
|
|
3
|
+
Common ESLint plugin for Bedrock projects. Note that this package uses flat config new to ESLint v9.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [Install](#install)
|
|
6
|
+
- [Usage](#usage)
|
|
7
|
+
- [VSCode](#vscode)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Install both [ESLint](http://eslint.org) and this plugin:
|
|
8
12
|
|
|
9
13
|
```
|
|
10
|
-
$ npm
|
|
14
|
+
$ npm install eslint @bedrockio/eslint-plugin --save-dev
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
You can now use the exported modules in a flat ESLint config:
|
|
14
20
|
|
|
15
|
-
```
|
|
16
|
-
|
|
21
|
+
```js
|
|
22
|
+
import { recommended, react, jest } from '@bedrockio/eslint-plugin';
|
|
23
|
+
|
|
24
|
+
export default [
|
|
25
|
+
jest,
|
|
26
|
+
react,
|
|
27
|
+
recommended,
|
|
28
|
+
{
|
|
29
|
+
// In most cases this won't be needed, however
|
|
30
|
+
// note that to scope rules to different files,
|
|
31
|
+
// configs will overwrite each other unless exported
|
|
32
|
+
// as an array so need to deep merge them together.
|
|
33
|
+
files: ['src/**/*.js'],
|
|
34
|
+
languageOptions: {
|
|
35
|
+
// Custom language options like babel transforms
|
|
36
|
+
// etc. Note that the exported react plugin is
|
|
37
|
+
// already set up to parse JSX. This complex
|
|
38
|
+
// setup is only if you have mixed environments
|
|
39
|
+
// in the same project.
|
|
40
|
+
},
|
|
41
|
+
plugins: {
|
|
42
|
+
...react.plugins,
|
|
43
|
+
...recommended.plugins,
|
|
44
|
+
},
|
|
45
|
+
settings: {
|
|
46
|
+
...react.settings,
|
|
47
|
+
...recommended.settings,
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
...react.rules,
|
|
51
|
+
...recommended.rules,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
|
17
55
|
```
|
|
18
56
|
|
|
57
|
+
## VSCode
|
|
19
58
|
|
|
20
|
-
|
|
59
|
+
Although not part of linting, getting intellisense in VSCode to work properly in a project is a pain. To make it work nicely add this to your project:
|
|
21
60
|
|
|
22
|
-
|
|
23
|
-
|
|
61
|
+
```jsonc
|
|
62
|
+
// jsconfig.json
|
|
24
63
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
64
|
+
"compilerOptions": {
|
|
65
|
+
// - import from "../../components"
|
|
66
|
+
// + import from "components"
|
|
67
|
+
"baseUrl": "./src",
|
|
68
|
+
// Support JSX if needed
|
|
69
|
+
"jsx": "react-jsx",
|
|
70
|
+
"checkJs": false,
|
|
71
|
+
// Makes package imports behave better.
|
|
72
|
+
"module": "nodenext",
|
|
73
|
+
// Helps with some commonjs modules.
|
|
74
|
+
"allowSyntheticDefaultImports": true
|
|
75
|
+
},
|
|
76
|
+
// Skip parsing useless files.
|
|
77
|
+
"exclude": ["dist", "build", "node_modules"]
|
|
30
78
|
}
|
|
31
|
-
```
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Another annoyance is module resolution for specific packages (specifically lodash and react-router):
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
// You can simply import "react-router-dom"
|
|
85
|
+
// but the intellisense isn't aware of this.
|
|
86
|
+
import { Link } from 'react-router-dom/cjs/react-router-dom.min';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To fix these kind of errors simply import the appropriate types:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install --save-dev @types/lodash
|
|
93
|
+
npm install --save-dev @types/react-router-dom
|
|
94
|
+
# ...etc
|
|
95
|
+
```
|
package/dist/cjs/mdx.js
CHANGED
|
@@ -10,6 +10,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
10
10
|
const plugin = {
|
|
11
11
|
...mdx.flat,
|
|
12
12
|
files: ['**/*.mdx'],
|
|
13
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
13
14
|
processor: mdx.createRemarkProcessor({
|
|
14
15
|
lintCodeBlocks: true
|
|
15
16
|
}),
|
package/dist/cjs/node-imports.js
CHANGED
|
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
function
|
|
7
|
+
var plugin = _interopRequireWildcard(require("eslint-plugin-import"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
10
|
var _default = exports.default = {
|
|
10
11
|
files: ['**/*.{js,jsx}'],
|
|
12
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
11
13
|
plugins: {
|
|
12
|
-
import:
|
|
14
|
+
import: plugin
|
|
13
15
|
},
|
|
14
16
|
rules: {
|
|
15
17
|
'import/no-unresolved': 'warn',
|
|
@@ -25,5 +27,12 @@ var _default = exports.default = {
|
|
|
25
27
|
}],
|
|
26
28
|
groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'index', 'object', 'type']
|
|
27
29
|
}]
|
|
30
|
+
},
|
|
31
|
+
settings: {
|
|
32
|
+
'import/resolver': {
|
|
33
|
+
node: {
|
|
34
|
+
moduleDirectory: ['node_modules', 'src']
|
|
35
|
+
}
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
};
|
package/dist/cjs/react.js
CHANGED
|
@@ -8,6 +8,7 @@ var _eslintPluginReact = _interopRequireDefault(require("eslint-plugin-react"));
|
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
var _default = exports.default = {
|
|
10
10
|
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
11
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
11
12
|
plugins: {
|
|
12
13
|
react: _eslintPluginReact.default
|
|
13
14
|
},
|
|
@@ -7,17 +7,16 @@ exports.default = void 0;
|
|
|
7
7
|
var plugin = _interopRequireWildcard(require("eslint-plugin-import"));
|
|
8
8
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
9
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
-
const {
|
|
11
|
-
parserOptions,
|
|
12
|
-
...rest
|
|
13
|
-
} = plugin.configs.recommended;
|
|
14
10
|
var _default = exports.default = {
|
|
15
|
-
...
|
|
16
|
-
files: ['**/*.{js,jsx}'],
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
...plugin.flatConfigs.recommended,
|
|
12
|
+
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
13
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
14
|
+
languageOptions: {
|
|
15
|
+
ecmaVersion: 'latest',
|
|
16
|
+
sourceType: 'module'
|
|
19
17
|
},
|
|
20
18
|
rules: {
|
|
19
|
+
...plugin.flatConfigs.recommended.rules,
|
|
21
20
|
'import/no-unresolved': ['warn', {
|
|
22
21
|
// package.json "style" may be used here which
|
|
23
22
|
// will resolve for webpack but not within the
|
|
@@ -67,10 +66,10 @@ var _default = exports.default = {
|
|
|
67
66
|
settings: {
|
|
68
67
|
'import/resolver': {
|
|
69
68
|
webpack: {
|
|
70
|
-
config: 'webpack.config.js'
|
|
69
|
+
config: './webpack.config.js'
|
|
71
70
|
},
|
|
72
71
|
node: {
|
|
73
|
-
|
|
72
|
+
moduleDirectory: ['node_modules', 'src']
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
}
|
package/package.json
CHANGED
package/src/mdx.js
CHANGED
package/src/node-imports.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import plugin from 'eslint-plugin-import';
|
|
1
|
+
import * as plugin from 'eslint-plugin-import';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
files: ['**/*.{js,jsx}'],
|
|
5
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
5
6
|
plugins: {
|
|
6
7
|
import: plugin,
|
|
7
8
|
},
|
|
@@ -34,4 +35,11 @@ export default {
|
|
|
34
35
|
},
|
|
35
36
|
],
|
|
36
37
|
},
|
|
38
|
+
settings: {
|
|
39
|
+
'import/resolver': {
|
|
40
|
+
node: {
|
|
41
|
+
moduleDirectory: ['node_modules', 'src'],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
37
45
|
};
|
package/src/react.js
CHANGED
package/src/webpack-imports.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as plugin from 'eslint-plugin-import';
|
|
2
2
|
|
|
3
|
-
const { parserOptions, ...rest } = plugin.configs.recommended;
|
|
4
|
-
|
|
5
3
|
export default {
|
|
6
|
-
...
|
|
7
|
-
files: ['**/*.{js,jsx}'],
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
...plugin.flatConfigs.recommended,
|
|
5
|
+
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
6
|
+
ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
|
|
7
|
+
languageOptions: {
|
|
8
|
+
ecmaVersion: 'latest',
|
|
9
|
+
sourceType: 'module',
|
|
10
10
|
},
|
|
11
11
|
rules: {
|
|
12
|
+
...plugin.flatConfigs.recommended.rules,
|
|
12
13
|
'import/no-unresolved': [
|
|
13
14
|
'warn',
|
|
14
15
|
{
|
|
@@ -83,10 +84,10 @@ export default {
|
|
|
83
84
|
settings: {
|
|
84
85
|
'import/resolver': {
|
|
85
86
|
webpack: {
|
|
86
|
-
config: 'webpack.config.js',
|
|
87
|
+
config: './webpack.config.js',
|
|
87
88
|
},
|
|
88
89
|
node: {
|
|
89
|
-
|
|
90
|
+
moduleDirectory: ['node_modules', 'src'],
|
|
90
91
|
},
|
|
91
92
|
},
|
|
92
93
|
},
|