@bedrockio/eslint-plugin 1.1.2 → 1.1.4

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 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
- ## Installation
5
+ - [Install](#install)
6
+ - [Usage](#usage)
7
+ - [VSCode](#vscode)
6
8
 
7
- You'll first need to install [ESLint](http://eslint.org):
9
+ ## Install
10
+
11
+ Install both [ESLint](http://eslint.org) and this plugin:
8
12
 
9
13
  ```
10
- $ npm i eslint --save-dev
14
+ $ npm install eslint @bedrockio/eslint-plugin --save-dev
11
15
  ```
12
16
 
13
- Next, install `eslint-plugin-bedrock`:
17
+ ## Usage
18
+
19
+ You can now use the exported modules in a flat ESLint config:
14
20
 
15
- ```
16
- $ npm install @bedrockio/eslint-plugin --save-dev
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
- ## Usage
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
- You can now extend from `recommended`, `react`, and `jest` configs.
23
- ```json
61
+ ```jsonc
62
+ // jsconfig.json
24
63
  {
25
- "extends": [
26
- "plugin:bedrock/recommended",
27
- "plugin:bedrock/jest",
28
- "plugin:bedrock/react"
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
  }),
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _eslintPluginImport = _interopRequireDefault(require("eslint-plugin-import"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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: _eslintPluginImport.default
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
- ...rest,
16
- files: ['**/*.{js,jsx}'],
17
- plugins: {
18
- import: plugin
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
@@ -31,33 +30,18 @@ var _default = exports.default = {
31
30
  pattern: 'semantic',
32
31
  group: 'external'
33
32
  }, {
34
- pattern: '+(stores|helpers|layouts)',
33
+ pattern: '+(stores|helpers|layouts|@stores|@helpers|@layouts){,/**}',
35
34
  group: 'internal',
36
35
  position: 'before'
37
36
  }, {
38
- pattern: '+(stores|helpers|layouts)/**',
39
- group: 'internal',
40
- position: 'before'
41
- }, {
42
- pattern: '+(screens|modals|components)',
37
+ pattern: '+(screens|modals|components|@screens|@modals|@components){,/**}',
43
38
  group: 'internal'
44
39
  }, {
45
- pattern: '+(screens|modals|components)/**',
46
- group: 'internal'
47
- }, {
48
- pattern: 'utils',
40
+ pattern: '+(utils|@utils){,/**}',
49
41
  group: 'internal',
50
42
  position: 'after'
51
43
  }, {
52
- pattern: 'utils/**',
53
- group: 'internal',
54
- position: 'after'
55
- }, {
56
- pattern: 'assets',
57
- group: 'sibling',
58
- position: 'after'
59
- }, {
60
- pattern: 'assets/**',
44
+ pattern: '+(assets|@assets){,**}',
61
45
  group: 'sibling',
62
46
  position: 'after'
63
47
  }],
@@ -67,10 +51,10 @@ var _default = exports.default = {
67
51
  settings: {
68
52
  'import/resolver': {
69
53
  webpack: {
70
- config: 'webpack.config.js'
54
+ config: './webpack.config.js'
71
55
  },
72
56
  node: {
73
- extensions: ['.mjs', '.js', '.jsx', '.json']
57
+ moduleDirectory: ['node_modules', 'src']
74
58
  }
75
59
  }
76
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/eslint-plugin",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Common ESLint plugin for Bedrock projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/mdx.js CHANGED
@@ -3,6 +3,7 @@ import * as mdx from 'eslint-plugin-mdx';
3
3
  const plugin = {
4
4
  ...mdx.flat,
5
5
  files: ['**/*.mdx'],
6
+ ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
6
7
  processor: mdx.createRemarkProcessor({
7
8
  lintCodeBlocks: true,
8
9
  }),
@@ -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
@@ -2,6 +2,7 @@ import react from 'eslint-plugin-react';
2
2
 
3
3
  export default {
4
4
  files: ['**/*.{js,jsx,ts,tsx}'],
5
+ ignores: ['node_modules/**/*', 'dist/**/*', '**/*.d.ts'],
5
6
  plugins: {
6
7
  react,
7
8
  },
@@ -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
- ...rest,
7
- files: ['**/*.{js,jsx}'],
8
- plugins: {
9
- import: plugin,
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
  {
@@ -29,40 +30,23 @@ export default {
29
30
  group: 'external',
30
31
  },
31
32
  {
32
- pattern: '+(stores|helpers|layouts)',
33
- group: 'internal',
34
- position: 'before',
35
- },
36
- {
37
- pattern: '+(stores|helpers|layouts)/**',
33
+ pattern:
34
+ '+(stores|helpers|layouts|@stores|@helpers|@layouts){,/**}',
38
35
  group: 'internal',
39
36
  position: 'before',
40
37
  },
41
38
  {
42
- pattern: '+(screens|modals|components)',
43
- group: 'internal',
44
- },
45
- {
46
- pattern: '+(screens|modals|components)/**',
39
+ pattern:
40
+ '+(screens|modals|components|@screens|@modals|@components){,/**}',
47
41
  group: 'internal',
48
42
  },
49
43
  {
50
- pattern: 'utils',
44
+ pattern: '+(utils|@utils){,/**}',
51
45
  group: 'internal',
52
46
  position: 'after',
53
47
  },
54
48
  {
55
- pattern: 'utils/**',
56
- group: 'internal',
57
- position: 'after',
58
- },
59
- {
60
- pattern: 'assets',
61
- group: 'sibling',
62
- position: 'after',
63
- },
64
- {
65
- pattern: 'assets/**',
49
+ pattern: '+(assets|@assets){,**}',
66
50
  group: 'sibling',
67
51
  position: 'after',
68
52
  },
@@ -83,10 +67,10 @@ export default {
83
67
  settings: {
84
68
  'import/resolver': {
85
69
  webpack: {
86
- config: 'webpack.config.js',
70
+ config: './webpack.config.js',
87
71
  },
88
72
  node: {
89
- extensions: ['.mjs', '.js', '.jsx', '.json'],
73
+ moduleDirectory: ['node_modules', 'src'],
90
74
  },
91
75
  },
92
76
  },