@fullstacksjs/eslint-config 7.0.3 → 8.0.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 CHANGED
@@ -58,16 +58,6 @@ Just extend from `@fullstacksjs`:
58
58
 
59
59
  It reads your root `package.json` dependencies and includes necessary rules.
60
60
 
61
- ## NextJS
62
-
63
- [NextJS](https://nextjs.org/) config is subset of base config which is compatible with builtin NextJS eslint config.
64
-
65
- ```json
66
- {
67
- "extends": ["@fullstacksjs/eslint-config/nextjs"]
68
- }
69
- ```
70
-
71
61
  ## Advanced Usage
72
62
 
73
63
  ```jsonc
@@ -79,6 +69,7 @@ It reads your root `package.json` dependencies and includes necessary rules.
79
69
  "@fullstacksjs/eslint-config/typescript",
80
70
  "@fullstacksjs/eslint-config/strict",
81
71
  "@fullstacksjs/eslint-config/cypress",
72
+ "@fullstacksjs/eslint-config/storybook",
82
73
  "@fullstacksjs/eslint-config/esm", // for native ESM modules
83
74
  "@fullstacksjs/eslint-config/typecheck" // ⚠️ Needs configurations (not included in default config)
84
75
  ]
@@ -115,7 +106,8 @@ If you need more advanced `typescript-eslint` rules, then you can extend from `"
115
106
  * eslint-plugin-simple-import-sort
116
107
  * eslint-plugin-fp
117
108
  * eslint-plugin-node
118
- * ~~eslint-plugin-promise~~ ⚠️ Disabled in v7-beta, because it's not currently supports eslint@8 ([Issue](https://github.com/xjamundx/eslint-plugin-promise/issues/218))
109
+ * eslint-plugin-promise
110
+ * eslint-plugin-storybook
119
111
 
120
112
  That's all. Feel free to use 💛
121
113
 
package/base.js CHANGED
@@ -1,12 +1,5 @@
1
1
  module.exports = {
2
- plugins: [
3
- 'prettier',
4
- 'import',
5
- 'simple-import-sort',
6
- // 'promise' PENDING: https://github.com/xjamundx/eslint-plugin-promise/issues/218
7
- 'node',
8
- 'fp',
9
- ],
2
+ plugins: ['prettier', 'import', 'simple-import-sort', 'promise', 'node', 'fp'],
10
3
  parserOptions: {
11
4
  ecmaVersion: 2020,
12
5
  sourceType: 'module',
@@ -34,7 +27,7 @@ module.exports = {
34
27
  './rules/style',
35
28
  './rules/variables',
36
29
  './rules/fp',
37
- // './rules/promise', PENDING: https://github.com/xjamundx/eslint-plugin-promise/issues/218
30
+ './rules/promise',
38
31
  './rules/node',
39
32
  'prettier',
40
33
  ],
package/bin/index.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ const createOptions = require('./lib/createOptions');
4
+ const createTasks = require('./lib/tasks');
5
+
6
+ createOptions()
7
+ .then(createTasks)
8
+ .then(tasks => tasks.run())
9
+ .catch(() => {});
@@ -0,0 +1,51 @@
1
+ const { readFile } = require('fs/promises');
2
+ const inquirer = require('inquirer');
3
+
4
+ const isObject = x => typeof x === 'object' && !Array.isArray(x) && x !== null;
5
+
6
+ // TODO: add this function to the toolbox
7
+ const merge = (obj, obj2) =>
8
+ Object.entries(obj)
9
+ .concat(Object.entries(obj2))
10
+ .reduce((acc, [key, value]) => {
11
+ const accValue = acc[key];
12
+ return Array.isArray(accValue) && Array.isArray(value)
13
+ ? { ...acc, [key]: accValue.concat(value) }
14
+ : isObject(accValue) && isObject(value)
15
+ ? { ...acc, [key]: merge(accValue, value) }
16
+ : { ...acc, [key]: value };
17
+ }, {});
18
+
19
+ const Choice = {
20
+ noConfig: 'noConfig',
21
+ overwrite: 'overwrite',
22
+ extend: 'extend',
23
+ };
24
+
25
+ const askWhenConfigExists = async eslintrc => {
26
+ const file = await readFile('.eslintrc.json').catch(() => null);
27
+ if (file === null) return eslintrc;
28
+
29
+ const currentConfig = JSON.parse(file);
30
+ const isConfiguredBefore = eslintrc?.extends.every(c => currentConfig?.extends?.includes(c));
31
+ if (isConfiguredBefore) return currentConfig;
32
+
33
+ const { choice } = await inquirer.prompt({
34
+ type: 'list',
35
+ name: 'choice',
36
+ message: 'config found',
37
+ choices: [
38
+ {
39
+ value: 'overwrite',
40
+ name: 'overwrite the current config completely',
41
+ },
42
+ {
43
+ value: 'extend',
44
+ name: 'extend the fullstacks config alongside current config',
45
+ },
46
+ ],
47
+ });
48
+ return choice === Choice.extend ? merge(currentConfig, eslintrc) : eslintrc;
49
+ };
50
+
51
+ module.exports = askWhenConfigExists;
@@ -0,0 +1,25 @@
1
+ const getUserInput = require('./getUserInput');
2
+ const args = require('./parseArgs');
3
+
4
+ const eslintrcConfig = {
5
+ extends: ['@fullstacksjs'],
6
+ };
7
+
8
+ const requiredPackages = ['@fullstacksjs/eslint-config', 'eslint', 'prettier'];
9
+
10
+ async function createOptions() {
11
+ const isTechnologyInArgv = args.t != null;
12
+ const optionsFromArgs = { technology: args.t };
13
+ const userInput = isTechnologyInArgv ? optionsFromArgs : await getUserInput();
14
+
15
+ if (userInput.technology === 'ts') {
16
+ requiredPackages.push('typescript');
17
+ }
18
+
19
+ return {
20
+ eslintrc: eslintrcConfig,
21
+ packages: requiredPackages,
22
+ };
23
+ }
24
+
25
+ module.exports = createOptions;
@@ -0,0 +1,15 @@
1
+ const { writeFile } = require('fs/promises');
2
+
3
+ function createFileTask(eslintrc, ctx, task) {
4
+ return writeFile('.eslintrc.json', JSON.stringify(eslintrc, null, 2))
5
+ .then(() => {
6
+ task.title = `.eslintrc - Successfully Generated.`;
7
+ })
8
+ .catch(() => {
9
+ ctx.isEslintrc = false;
10
+ task.title = `Generating .eslintrc file`;
11
+ throw Error("Couldn't create file");
12
+ });
13
+ }
14
+
15
+ module.exports = createFileTask;
@@ -0,0 +1,24 @@
1
+ const inquirer = require('inquirer');
2
+
3
+ function getUserInput() {
4
+ return inquirer.prompt([
5
+ {
6
+ type: 'list',
7
+ name: 'technology',
8
+ message: 'which technology are you using?',
9
+ choices: [
10
+ {
11
+ value: 'ts',
12
+ name: 'ESLint alongside TypeScript',
13
+ },
14
+ {
15
+ value: 'js',
16
+ name: 'ESLint for JavaScript development',
17
+ },
18
+ ],
19
+ default: 'js',
20
+ },
21
+ ]);
22
+ }
23
+
24
+ module.exports = getUserInput;
@@ -0,0 +1,12 @@
1
+ const yargs = require('yargs');
2
+
3
+ const args = yargs(process.argv.slice(2))
4
+ .alias('t', 'technology')
5
+ .describe('t', 'Which technology are you using')
6
+ .choices('t', ['ts', 'js'])
7
+ .usage('Usage: $0 [-t ts|js]')
8
+ .example('$0 - ts')
9
+ .help('h')
10
+ .alias('h', 'help').argv;
11
+
12
+ module.exports = args;
@@ -0,0 +1,30 @@
1
+ const Listr = require('listr');
2
+ const util = require('util');
3
+ const askWhenConfigExists = require('./askWhenConfigExists');
4
+ const exec = util.promisify(require('child_process').exec);
5
+ const createFileTask = require('./generateFile');
6
+
7
+ async function createTasks({ packages, eslintrc }) {
8
+ const installTasks = packages.map(pkg => ({
9
+ title: `Installing ${pkg}`,
10
+ task: (ctx, task) => exec(`npm i -D ${pkg}`).then(() => (task.title = `${pkg} Installed`)),
11
+ }));
12
+
13
+ const config = await askWhenConfigExists(eslintrc);
14
+
15
+ return new Listr(
16
+ [
17
+ {
18
+ title: 'Installing dependencies using npm',
19
+ task: () => new Listr(installTasks, { exitOnError: true }),
20
+ },
21
+ {
22
+ title: 'Generating .eslintrc.json file',
23
+ task: (ctx, task) => createFileTask(config, ctx, task),
24
+ },
25
+ ],
26
+ { exitOnError: false },
27
+ );
28
+ }
29
+
30
+ module.exports = createTasks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstacksjs/eslint-config",
3
- "version": "7.0.3",
3
+ "version": "8.0.0",
4
4
  "license": "MIT",
5
5
  "author": "fullstacks <fullstacksjs@gmail.com>",
6
6
  "description": "fullstacks eslint config",
@@ -11,13 +11,17 @@
11
11
  "publishConfig": {
12
12
  "registry": "https://registry.npmjs.org"
13
13
  },
14
+ "bin": {
15
+ "fullstacksjs-eslint": "./bin/index.js"
16
+ },
14
17
  "files": [
18
+ "bin",
15
19
  "rules",
16
20
  "base.js",
17
21
  "index.js",
18
22
  "jest.js",
19
23
  "cypress.js",
20
- "nextjs.js",
24
+ "storybook.js",
21
25
  "react.js",
22
26
  "typescript.js",
23
27
  "typecheck.js",
@@ -45,19 +49,24 @@
45
49
  "eslint-plugin-cypress": "2.12.1",
46
50
  "eslint-plugin-fp": "2.3.0",
47
51
  "eslint-plugin-import": "2.25.3",
48
- "eslint-plugin-jest-formatting": "3.1.0",
49
52
  "eslint-plugin-jest": "25.3.0",
53
+ "eslint-plugin-jest-formatting": "3.1.0",
50
54
  "eslint-plugin-jsx-a11y": "6.5.1",
51
55
  "eslint-plugin-node": "11.1.0",
52
56
  "eslint-plugin-prettier": "4.0.0",
53
- "eslint-plugin-react-hooks": "4.3.0",
57
+ "eslint-plugin-promise": "6.0.0",
54
58
  "eslint-plugin-react": "7.27.1",
59
+ "eslint-plugin-react-hooks": "4.3.0",
55
60
  "eslint-plugin-simple-import-sort": "7.0.0",
61
+ "eslint-plugin-storybook": "0.5.6",
62
+ "inquirer": "8.2.0",
63
+ "listr": "0.14.3",
56
64
  "lodash.has": "4.5.2",
57
- "read-pkg-up": "7.0.1"
65
+ "read-pkg-up": "7.0.1",
66
+ "yargs": "17.3.1"
58
67
  },
59
68
  "devDependencies": {
60
- "eslint": "8.4.1",
69
+ "eslint": "8.5.0",
61
70
  "eslint-find-rules": "4.0.0",
62
71
  "husky": "7.0.4",
63
72
  "lint-staged": "12.1.2",
@@ -65,14 +74,14 @@
65
74
  "npm-run-all": "4.1.5",
66
75
  "pinst": "2.1.6",
67
76
  "prettier": "2.5.1",
68
- "typescript": "4.5.2"
77
+ "typescript": "4.5.4"
69
78
  },
70
79
  "peerDependencies": {
80
+ "cypress": ">=8",
71
81
  "eslint": ">=7",
72
82
  "prettier": "2",
73
83
  "react": ">=16",
74
- "typescript": "4",
75
- "cypress": ">=8"
84
+ "typescript": "4"
76
85
  },
77
86
  "peerDependenciesMeta": {
78
87
  "typescript": {
package/rules/es2015.js CHANGED
@@ -25,5 +25,6 @@ module.exports = {
25
25
  'prefer-template': 'error',
26
26
  'require-yield': 'error',
27
27
  'symbol-description': 'error',
28
+ 'prefer-object-has-own': 'warn',
28
29
  },
29
30
  };
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ rules: {
3
+ 'storybook/await-interactions': 'error',
4
+ 'storybook/context-in-play-function': 'error',
5
+ 'storybook/default-exports': 'error',
6
+ 'storybook/hierarchy-separator': 'warn',
7
+ 'storybook/no-redundant-story-name': 'warn',
8
+ 'storybook/prefer-pascal-case': 'warn',
9
+ 'storybook/story-exports': 'error',
10
+ 'storybook/use-storybook-expect': 'error',
11
+ 'storybook/use-storybook-testing-library': 'error',
12
+
13
+ 'storybook/csf-component': 'warn',
14
+ 'storybook/no-stories-of': 'warn',
15
+ 'storybook/no-title-property-in-meta': 'warn',
16
+ },
17
+ };
package/rules/strict.js CHANGED
@@ -16,6 +16,10 @@ module.exports = {
16
16
  selector: 'default',
17
17
  format: ['camelCase'],
18
18
  },
19
+ {
20
+ selector: 'function',
21
+ format: ['camelCase', 'PascalCase'],
22
+ },
19
23
  // variables, CONSTANTS, ReactComponents
20
24
  {
21
25
  selector: 'variable',
@@ -23,7 +27,7 @@ module.exports = {
23
27
  },
24
28
  {
25
29
  selector: 'parameter',
26
- format: ['camelCase'],
30
+ format: ['camelCase', 'PascalCase'],
27
31
  leadingUnderscore: 'allow',
28
32
  },
29
33
  {
@@ -29,6 +29,58 @@ module.exports = {
29
29
  '@typescript-eslint/member-naming': 'off',
30
30
  '@typescript-eslint/member-ordering': 'off',
31
31
  '@typescript-eslint/method-signature-style': ['warn', 'property'],
32
+ '@typescript-eslint/naming-convention': [
33
+ 'warn',
34
+ {
35
+ selector: 'default',
36
+ format: ['camelCase'],
37
+ },
38
+ {
39
+ selector: 'function',
40
+ format: ['camelCase', 'PascalCase'],
41
+ },
42
+ // variables, CONSTANTS, ReactComponents
43
+ {
44
+ selector: 'variable',
45
+ format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
46
+ },
47
+ {
48
+ selector: 'parameter',
49
+ format: ['camelCase', 'PascalCase'],
50
+ leadingUnderscore: 'allow',
51
+ },
52
+ {
53
+ selector: 'memberLike',
54
+ format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
55
+ leadingUnderscore: 'allow',
56
+ },
57
+ {
58
+ selector: 'memberLike',
59
+ modifiers: ['static'],
60
+ format: ['camelCase', 'PascalCase'],
61
+ leadingUnderscore: 'allow',
62
+ },
63
+ {
64
+ selector: 'memberLike',
65
+ modifiers: ['private'],
66
+ format: ['camelCase'],
67
+ leadingUnderscore: 'allow',
68
+ },
69
+ {
70
+ selector: 'typeLike',
71
+ format: ['PascalCase'],
72
+ },
73
+ {
74
+ selector: 'enumMember',
75
+ format: ['PascalCase'],
76
+ },
77
+ // disallow I prefix for interfaces
78
+ {
79
+ selector: 'interface',
80
+ format: ['PascalCase'],
81
+ custom: { regex: '^I[A-Z]', match: false },
82
+ },
83
+ ],
32
84
  '@typescript-eslint/no-array-constructor': 'error',
33
85
  '@typescript-eslint/no-base-to-string': 'off', // false negative
34
86
  '@typescript-eslint/no-confusing-non-null-assertion': 'error',
package/storybook.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ overrides: [
3
+ {
4
+ plugin: ['storybook'],
5
+ files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
6
+ extends: ['./rules/storybook.js'],
7
+ },
8
+ ],
9
+ };
package/nextjs.js DELETED
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- plugins: ['prettier', 'simple-import-sort', 'promise', 'node', 'fp'],
3
- parserOptions: {
4
- ecmaVersion: 2020,
5
- sourceType: 'module',
6
- requireConfigFile: false,
7
- },
8
- env: {
9
- browser: true,
10
- es6: true,
11
- node: true,
12
- },
13
- extends: [
14
- './rules/base',
15
- './rules/es2015',
16
- './rules/forbidden',
17
- './rules/style',
18
- './rules/variables',
19
- './rules/fp',
20
- './rules/promise',
21
- './rules/node',
22
- 'prettier',
23
- ],
24
- };