@fullstacksjs/eslint-config 9.0.14 → 9.0.15

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
@@ -40,93 +40,81 @@ $ npm install --save-dev @fullstacksjs/eslint-config eslint prettier
40
40
  $ yarn add --dev @fullstacksjs/eslint-config eslint prettier
41
41
  ```
42
42
 
43
- optional dependencies (if you need):
44
-
45
- * react
46
- * jest
47
- * cypress
48
-
49
43
  ## Usage
50
44
 
51
- Just extend from `@fullstacksjs`:
45
+ ## Method 1 (recommended)
52
46
 
53
- ```json
54
- {
55
- "extends": ["@fullstacksjs"]
56
- }
57
- ```
47
+ Create `.eslintrc.js` file and init the configuration.
48
+
49
+ ```js
50
+ const { init } = require('@fullstacksjs/eslint-config/init');
58
51
 
59
- It reads your root `package.json` dependencies and includes necessary rules.
52
+ module.exports = init({
53
+ modules: {
54
+ auto: true, // If you need auto module detection.
55
+ // Modules configuration. (optional)
56
+ },
57
+ // Your configurations
58
+ });
60
59
 
61
- ## NextJS
60
+ ```
62
61
 
63
- Our index setup conflicts with the built-in ESLint [NextJS](https://nextjs.org/) configuration. To utilize it in a NextJS project, configure your eslintrc file as follows.
62
+ ## Method 2
63
+ extend from `@fullstacksjs`:
64
64
 
65
65
  ```json
66
66
  {
67
- "extends": ["next/core-web-vitals", "@fullstacksjs/eslint-config/nextjs"]
67
+ "extends": ["@fullstacksjs"]
68
68
  }
69
69
  ```
70
70
 
71
- ## Advanced Usage
72
-
73
- ```jsonc
74
- {
75
- "extends": [
76
- "@fullstacksjs/eslint-config/base",
77
- "@fullstacksjs/eslint-config/jest",
78
- "@fullstacksjs/eslint-config/react",
79
- "@fullstacksjs/eslint-config/typescript",
80
- "@fullstacksjs/eslint-config/strict",
81
- "@fullstacksjs/eslint-config/cypress",
82
- "@fullstacksjs/eslint-config/storybook",
83
- "@fullstacksjs/eslint-config/graphql", // Need extra config
84
- "@fullstacksjs/eslint-config/esm", // for native ESM modules
85
- "@fullstacksjs/eslint-config/typecheck" // ⚠️ Needs configurations (not included in default config)
86
- ]
71
+ ## Auto Module Detection
72
+ When you extend from `@fullstakcjs` or use `modules.auto: true`, it reads your root `package.json` dependencies and includes necessary rules and plugins.
73
+
74
+ ## Modules API
75
+
76
+ ```typescript
77
+ interface Modules {
78
+ auto?: boolean; // Auto module detection
79
+ react?: 'next' | 'raw'; // controls react, react-hooks, jsx/a11y plugins
80
+ typescript?: { parserProject: string[] | string; resolverProject: string[] | string }; // controls typescript plugin
81
+ node?: boolean; // controls node plugin
82
+ strict?: boolean; // controls strict plugin
83
+ import?: boolean; // controls import plugin
84
+ esm?: boolean; // controls esm plugin
85
+ graphql?: boolean; // controls graphql plugin
86
+ test?: boolean; // controls jest/vitest plugin
87
+ cypress?: boolean; // controls cypress plugin
88
+ storybook?: boolean; // controls storybook plugin
87
89
  }
88
90
  ```
89
91
 
90
- ## Need more typescript rules?
92
+ ## Typescript configuration
91
93
 
92
- If you need more advanced `typescript-eslint` rules, then you can extend from `"@fullstacksjs/eslint-config/typecheck"` and set `parserOptions.project` option:
94
+ If you need more advanced typescript-eslint rule you need to specify `modules.typescript.resolverProject`.
93
95
 
94
96
  ```json
95
- {
96
- "extends": [
97
- "@fullstacksjs",
98
- "@fullstacksjs/eslint-config/typecheck"
99
- ],
100
- "parserOptions": {
101
- "project": "<PATH_TO_TSCONFIG>"
102
- }
103
- }
97
+ module.exports = init({
98
+ modules: {
99
+ typescript: { resolverProject: "<PATH_TO_TSCONFIG>" }
100
+ },
101
+ });
104
102
  ```
105
103
 
106
104
  ## Graphql
107
105
 
108
- To enable graphql module you need to extends from `@fullstacksjs/eslint-config/graphql` and configure schema and operations in you eslint config or graphql config. for more information checkout [here](https://github.com/B2o5T/graphql-eslint#configuration).
106
+ To enable graphql module you need to set either have `graphql` dependency installed with auto module detection option, or manually enable it yourself by `modules.graphql` option. for more information checkout [here](https://github.com/B2o5T/graphql-eslint#configuration).
109
107
 
110
108
  Here is an example:
111
109
 
112
- ```jsonc
113
- // eslintrc
114
-
115
- {
116
- "extends": [
117
- ...
118
- "@fullstacksjs/eslint-config/graphql"
119
- ],
120
- }
121
- ```
122
-
123
- ```yaml
124
- # .graphqlrc.yml
125
-
126
- schema: 'path/to/schema'
110
+ ```js
111
+ module.exports = init({
112
+ modules: {
113
+ graphql: true
114
+ },
115
+ });
127
116
  ```
128
117
 
129
-
130
118
  ## What's included?
131
119
 
132
120
  * @typescript-eslint/eslint-plugin
package/cypress.js CHANGED
@@ -6,7 +6,7 @@ const { exts } = require('./utils');
6
6
  module.exports = {
7
7
  overrides: [
8
8
  {
9
- files: [`**/cypress/**/*.${exts}`, `**/*.cy.+${exts}`],
9
+ files: [`**/cypress/**/*.${exts}`, `**/*.cy.${exts}`],
10
10
  plugins: ['jest', 'jest-formatting', 'cypress'],
11
11
  env: {
12
12
  'cypress/globals': true,
package/esm.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /** @type { import('eslint').Linter.Config } */
2
2
  module.exports = {
3
3
  rules: {
4
- 'import/extensions': ['error', { mjs: 'ignorePackages' }],
4
+ ...(global.fullstacksjs?.import && { 'import/extensions': ['error', { mjs: 'ignorePackages' }] }),
5
5
  },
6
6
  overrides: [
7
7
  {
8
8
  files: ['*.ts', '*.tsx'],
9
9
  rules: {
10
- 'import/no-unresolved': ['error', { ignore: ['.js$'], caseSensitiveStrict: true }],
10
+ ...(global.fullstacksjs?.import && { 'import/no-unresolved': ['error', { ignore: ['.js$'], caseSensitiveStrict: true }] }),
11
11
  },
12
12
  },
13
13
  ],
package/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  require('./registerOpts');
2
- const { compact } = require('@fullstacksjs/toolbox');
3
2
 
4
3
  /** @type { import('eslint').Linter.Config } */
5
4
  module.exports = {
6
- extends: compact([
5
+ extends: [
7
6
  require.resolve('./base'),
8
7
  require.resolve('./fp'),
9
8
  require.resolve('./import'),
@@ -15,5 +14,5 @@ module.exports = {
15
14
  global.fullstacksjs?.typescript && require.resolve('./typescript'),
16
15
  global.fullstacksjs?.cypress && require.resolve('./cypress'),
17
16
  require.resolve('./prettier'),
18
- ]),
17
+ ].filter(Boolean),
19
18
  };
package/init.d.ts CHANGED
@@ -1,15 +1,18 @@
1
- export interface Options {
2
- react: 'next' | 'raw';
3
- typescript: { parserProject: string[] | string; resolverProject: string[] | string };
4
- node: boolean;
5
- strict: boolean;
6
- import: boolean;
7
- esm: boolean;
8
- graphql: boolean;
9
- test: boolean;
10
- cypress: boolean;
11
- storybook: boolean;
12
- overrides: import('eslint').Linter.Config;
1
+ type Config = import('eslint').Linter.Config;
2
+ export interface Options extends Config {
3
+ modules: {
4
+ auto?: boolean;
5
+ react?: 'next' | 'raw';
6
+ typescript?: { parserProject: string[] | string; resolverProject: string[] | string };
7
+ node?: boolean;
8
+ strict?: boolean;
9
+ import?: boolean;
10
+ esm?: boolean;
11
+ graphql?: boolean;
12
+ test?: boolean;
13
+ cypress?: boolean;
14
+ storybook?: boolean;
15
+ };
13
16
  }
14
17
 
15
18
  export declare const init: (opts: Options) => import('eslint').Linter.Config;
package/init.js CHANGED
@@ -1,34 +1,38 @@
1
- require('./registerOpts');
2
- const { compact } = require('@fullstacksjs/toolbox');
3
1
  const merge = require('deepmerge');
4
2
 
5
3
  /** @param { import('./init.d').Options } opts */
6
4
  // eslint-disable-next-line complexity
7
5
  function init(opts = {}) {
8
- const { extends: extendsOverrides, ...overrides } = opts.overrides;
9
- global.fullstacksjs = merge(global.fullstacksjs, opts);
6
+ const { modules = {}, extends: extraExtends = [], ...eslintConfig } = opts;
7
+ if (modules.auto) {
8
+ require('./registerOpts');
9
+ global.fullstacksjs = merge(global.fullstacksjs, modules);
10
+ } else {
11
+ global.fullstacksjs = modules;
12
+ }
13
+ opts = global.fullstacksjs;
10
14
 
11
15
  /** @type { import('eslint').Linter.Config } */
12
16
  const config = {
13
- extends: compact([
17
+ extends: [
14
18
  require.resolve('./base'),
15
19
  require.resolve('./promise'),
16
20
  require.resolve('./fp'),
17
21
  opts.node && require.resolve('./node'),
18
- opts.cypress && require.resolve('./cypress'),
19
- opts.test && require.resolve('./jest'),
20
22
  opts.graphql && require.resolve('./graphql'),
21
- opts.storybook && require.resolve('./storybook'),
22
- opts.importModule && require.resolve('./import'),
23
+ opts.import && require.resolve('./import'),
23
24
  opts.typescript && require.resolve('./typescript'),
25
+ opts.storybook && require.resolve('./storybook'),
26
+ opts.cypress && require.resolve('./cypress'),
27
+ opts.test && require.resolve('./jest'),
24
28
  opts.esm && require.resolve('./esm'),
25
29
  opts.strict && require.resolve('./strict'),
26
30
  require.resolve('./prettier'),
27
- ...(extendsOverrides ?? []),
28
- ]),
31
+ ...extraExtends,
32
+ ].filter(Boolean),
29
33
  parserOptions: {},
30
34
  settings: {},
31
- ...overrides,
35
+ ...eslintConfig,
32
36
  };
33
37
 
34
38
  if (opts.react === 'raw') config.extends.push(require.resolve('./react.js'));
package/jest.js CHANGED
@@ -68,7 +68,7 @@ module.exports = {
68
68
  'jest/no-deprecated-functions': 'error',
69
69
  }),
70
70
 
71
- ...(global.fullstacksjs?.typescript && {
71
+ ...(global.fullstacksjs?.typescript?.resolverProject && {
72
72
  '@typescript-eslint/unbound-method': 'off',
73
73
  'jest/unbound-method': 'error',
74
74
  'jest/no-untyped-mock-factory': 'warn',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstacksjs/eslint-config",
3
- "version": "9.0.14",
3
+ "version": "9.0.15",
4
4
  "license": "MIT",
5
5
  "author": "fullstacks <fullstacksjs@gmail.com>",
6
6
  "description": "fullstacks eslint config",
package/registerOpts.js CHANGED
@@ -6,7 +6,7 @@ const defaultOptions = {
6
6
  cypress: hasDep('cypress'),
7
7
  graphql: hasDep('graphql'),
8
8
  react: hasDep('react') && !hasDep('next'),
9
- storybook: hasDep('storybook'),
9
+ storybook: hasDep('@storybook/react'),
10
10
  test: hasDep('jest') || hasDep('vitest'),
11
11
  typescript: hasDep('typescript'),
12
12
  import: true,
package/storybook.js CHANGED
@@ -2,8 +2,8 @@
2
2
  module.exports = {
3
3
  overrides: [
4
4
  {
5
+ files: ['**/*.stories.+(ts|tsx|js|jsx|mjs|cjs|mdx)', '**/*.story.+(ts|tsx|js|jsx|mjs|cjs|mdx)'],
5
6
  plugins: ['storybook'],
6
- files: ['*.stories.+(ts|tsx|js|jsx|mjs|cjs|mdx)', '*.story.+(ts|tsx|js|jsx|mjs|cjs|mdx)'],
7
7
  rules: {
8
8
  'storybook/await-interactions': 'error',
9
9
  'storybook/context-in-play-function': 'error',