@jgarber/eslint-config 1.1.0 → 2.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
@@ -1,10 +1,13 @@
1
1
  # eslint-config
2
2
 
3
- Shareable [ESLint](https://eslint.org) configuration.
3
+ Shareable [ESLint](https://eslint.org) configurations.
4
4
 
5
- > **Note**
6
- >
7
- > As of v1.0.0, this shareable configuration uses ESLint's new "flat" configuration file format and, thus, may not be suitable for every project. See [the official documentation](https://eslint.org/docs/latest/use/configure/configuration-files-new) for details.
5
+ [![npm](https://img.shields.io/npm/v/@jgarber/eslint-config.svg?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/@jgarber/eslint-config)
6
+ [![Downloads](https://img.shields.io/npm/dt/@jgarber/eslint-config.svg?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/@jgarber/eslint-config)
7
+ [![Build](https://img.shields.io/github/actions/workflow/status/jgarber623/eslint-config/ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/jgarber623/eslint-config/actions/workflows/ci.yml)
8
+
9
+ > [!IMPORTANT]\
10
+ > These shareable configurations use ESLint's new "flat" configuration file format, which may not be suitable for every project. See [the official documentation](https://eslint.org/docs/latest/use/configure/configuration-files-new) for details.
8
11
 
9
12
  ## Installation
10
13
 
@@ -14,26 +17,35 @@ npm install --save-dev @jgarber/eslint-config
14
17
 
15
18
  ## Usage
16
19
 
17
- Using [CommonJS module](https://nodejs.org/api/modules.html) syntax:
20
+ Using [ECMAScript module (ESM)](https://nodejs.org/api/esm.html) syntax:
18
21
 
19
22
  ```js
20
23
  // eslint.config.js
21
- module.exports = require('@jgarber/eslint-config');
24
+ import config from '@jgarber/eslint-config';
25
+
26
+ export default config;
22
27
  ```
23
28
 
24
- Using [ECMAScript module (ESM)](https://nodejs.org/api/esm.html) syntax:
29
+ Using [CommonJS module](https://nodejs.org/api/modules.html) syntax:
25
30
 
26
31
  ```js
27
32
  // eslint.config.js
28
- import config from '@jgarber/eslint-config';
33
+ const config = require('@jgarber/eslint-config');
34
+ const commonjs = require('@jgarber/eslint-config/commonjs');
29
35
 
30
- export default [
31
- ...config,
32
- {
33
- files: ['**/*.js'],
34
- languageOptions: {
35
- sourceType: 'module'
36
- }
37
- }
36
+ module.exports = [
37
+ ...commonjs,
38
+ ...config
38
39
  ];
39
40
  ```
41
+
42
+ ### Additional Configurations
43
+
44
+ This package exports several other configurations that may be useful in conjunction with the main configuration (or, by themselves!):
45
+
46
+ - `@jgarber/eslint-config/commonjs`: configures `languageOptions` and `globals` for CommonJS modules (especially useful if your `*.js` files target Node.js environments)
47
+ - `@jgarber/eslint-config/ava`: configures linting for tests written using the [AVA](https://www.npmjs.com/package/ava) test framework
48
+
49
+ ## License
50
+
51
+ Ths package is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
package/lib/ava.js ADDED
@@ -0,0 +1,22 @@
1
+ const ava = require('eslint-plugin-ava');
2
+
3
+ module.exports = [
4
+ {
5
+ // Use AVA's default file-matching patterns.
6
+ //
7
+ // https://github.com/avajs/ava/blob/HEAD/docs/05-command-line.md
8
+ files: [
9
+ 'test.js',
10
+ 'src/test.js',
11
+ 'source/test.js',
12
+ '**/test-*.js',
13
+ '**/*.spec.js',
14
+ '**/*.test.js',
15
+ '**/test/**/*.js',
16
+ '**/tests/**/*.js',
17
+ '**/__tests__/**/*.js'
18
+ ],
19
+ plugins: { ava },
20
+ rules: ava.configs.recommended.rules
21
+ }
22
+ ];
@@ -0,0 +1,29 @@
1
+ // By default, ESLint's "flat" config considers `*.js` files to be ECMAScript
2
+ // modules (ESM). `*.mjs` files are always parsed as ESM modules and `*.cjs`
3
+ // files are always parsed as CommonJS modules.
4
+ //
5
+ // This configures ESLint to treat `*.js` files as CommonJS modules.
6
+ //
7
+ // Authors may also specify the module type in `package.json` using either
8
+ // `"type": "commonjs"` or `"type": "module"`.
9
+ //
10
+ // https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects
11
+ // https://nodejs.org/dist/latest-v18.x/docs/api/modules.html#enabling
12
+ module.exports = [
13
+ {
14
+ files: ['**/*.js'],
15
+ languageOptions: {
16
+ // https://www.npmjs.com/package/globals
17
+ // https://github.com/sindresorhus/globals/blob/HEAD/globals.json
18
+ globals: {
19
+ __dirname: 'readonly',
20
+ __filename: 'readonly',
21
+ exports: 'writable',
22
+ global: 'readonly',
23
+ module: 'readonly',
24
+ require: 'readonly'
25
+ },
26
+ sourceType: 'commonjs'
27
+ }
28
+ }
29
+ ];
@@ -0,0 +1,21 @@
1
+ const plugin = require('eslint-plugin-array-func');
2
+ const { configs, rules } = plugin;
3
+
4
+ module.exports = {
5
+ configs: {
6
+ 'flat/all': {
7
+ plugins: { 'array-func': plugin },
8
+ rules: {
9
+ ...configs.recommended.rules,
10
+ ...configs.all.rules
11
+ }
12
+ },
13
+ 'flat/recommended': {
14
+ plugins: { 'array-func': plugin },
15
+ rules: {
16
+ ...configs.recommended.rules
17
+ }
18
+ }
19
+ },
20
+ rules
21
+ };
@@ -0,0 +1,12 @@
1
+ const plugin = require('eslint-plugin-promise');
2
+ const { configs, rules } = plugin;
3
+
4
+ module.exports = {
5
+ configs: {
6
+ 'flat/recommended': {
7
+ plugins: { promise: plugin },
8
+ rules: configs.recommended.rules
9
+ }
10
+ },
11
+ rules
12
+ };
@@ -0,0 +1,16 @@
1
+ const plugin = require('eslint-plugin-regexp');
2
+ const { configs, rules } = plugin;
3
+
4
+ module.exports = {
5
+ configs: {
6
+ 'flat/all': {
7
+ plugins: { regexp: plugin },
8
+ rules: configs.all.rules
9
+ },
10
+ 'flat/recommended': {
11
+ plugins: { regexp: plugin },
12
+ rules: configs.recommended.rules
13
+ }
14
+ },
15
+ rules
16
+ };
@@ -0,0 +1,12 @@
1
+ const plugin = require('eslint-plugin-sort-class-members');
2
+ const { configs, rules } = plugin;
3
+
4
+ module.exports = {
5
+ configs: {
6
+ 'flat/recommended': {
7
+ plugins: { 'sort-class-members': plugin },
8
+ rules: configs.recommended.rules
9
+ }
10
+ },
11
+ rules
12
+ };
@@ -0,0 +1,16 @@
1
+ const plugin = require('eslint-plugin-unicorn');
2
+ const { configs, rules } = plugin;
3
+
4
+ module.exports = {
5
+ configs: {
6
+ 'flat/all': {
7
+ plugins: { unicorn: plugin },
8
+ rules: configs.all.rules
9
+ },
10
+ 'flat/recommended': {
11
+ plugins: { unicorn: plugin },
12
+ rules: configs.recommended.rules
13
+ }
14
+ },
15
+ rules
16
+ };
@@ -0,0 +1,5 @@
1
+ module.exports.arrayFunc = require('./eslint-plugin-array-func');
2
+ module.exports.promise = require('./eslint-plugin-promise');
3
+ module.exports.regexp = require('./eslint-plugin-regexp');
4
+ module.exports.sortClassMembers = require('./eslint-plugin-sort-class-members');
5
+ module.exports.unicorn = require('./eslint-plugin-unicorn');
package/lib/index.js ADDED
@@ -0,0 +1,88 @@
1
+ // ESLint shared configurations
2
+ const js = require('@eslint/js');
3
+ const standard = require('eslint-config-standard');
4
+
5
+ // ESLint plugins
6
+ const jsdoc = require('eslint-plugin-jsdoc');
7
+ const n = require('eslint-plugin-n');
8
+
9
+ // Compat module for non-"flat"-compatible plugins
10
+ const compat = require('./compat');
11
+
12
+ module.exports = [
13
+ // https://www.npmjs.com/package/eslint-plugin-jsdoc
14
+ jsdoc.configs['flat/recommended-error'],
15
+
16
+ // https://www.npmjs.com/package/eslint-plugin-n
17
+ n.configs['flat/recommended'],
18
+
19
+ // https://www.npmjs.com/package/eslint-plugin-array-func
20
+ compat.arrayFunc.configs['flat/all'],
21
+
22
+ // https://www.npmjs.com/package/eslint-plugin-promise
23
+ compat.promise.configs['flat/recommended'],
24
+
25
+ // https://www.npmjs.com/package/eslint-plugin-regexp
26
+ compat.regexp.configs['flat/recommended'],
27
+
28
+ // https://www.npmjs.com/package/eslint-plugin-sort-class-members
29
+ compat.sortClassMembers.configs['flat/recommended'],
30
+
31
+ // https://www.npmjs.com/package/eslint-plugin-unicorn
32
+ compat.unicorn.configs['flat/recommended'],
33
+
34
+ {
35
+ rules: {
36
+ // https://www.npmjs.com/package/@eslint/js
37
+ ...js.configs.recommended.rules,
38
+
39
+ // https://www.npmjs.com/package/eslint-config-standard
40
+ //
41
+ // Remove eslint-plugin-import rules until the following "flat" config-
42
+ // related issues are resolved.
43
+ //
44
+ // https://github.com/import-js/eslint-plugin-import/issues/2556
45
+ // https://github.com/import-js/eslint-plugin-import/pull/2829
46
+ ...Object.fromEntries(
47
+ Object.entries(standard.rules).filter(([key]) => {
48
+ return !key.startsWith('import/');
49
+ })
50
+ ),
51
+
52
+ // https://eslint.org/docs/latest/rules/semi
53
+ semi: ['error', 'always'],
54
+
55
+ // https://eslint.org/docs/latest/rules/sort-keys
56
+ 'sort-keys': ['error', 'asc', {
57
+ allowLineSeparatedGroups: true,
58
+ natural: true
59
+ }],
60
+
61
+ // https://eslint.org/docs/latest/rules/space-before-function-paren
62
+ 'space-before-function-paren': ['error', {
63
+ anonymous: 'never',
64
+ asyncArrow: 'always',
65
+ named: 'never'
66
+ }],
67
+
68
+ // Disable rules conflicting with eslint-plugin-unicorn.
69
+ //
70
+ // https://www.npmjs.com/package/eslint-plugin-array-func
71
+ 'array-func/prefer-flat': 'off',
72
+ 'array-func/prefer-flat-map': 'off',
73
+
74
+ // https://github.com/gajus/eslint-plugin-jsdoc/blob/HEAD/docs/rules/tag-lines.md
75
+ 'jsdoc/tag-lines': ['error', 'any', { startLines: 1 }],
76
+
77
+ // ¯\_(ツ)_/¯
78
+ //
79
+ // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/no-null.md}
80
+ // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-module.md}
81
+ 'unicorn/no-null': 'off',
82
+ 'unicorn/prefer-module': 'off',
83
+
84
+ // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prevent-abbreviations.md
85
+ 'unicorn/prevent-abbreviations': ['warn', { checkFilenames: false }]
86
+ }
87
+ }
88
+ ];
package/package.json CHANGED
@@ -1,36 +1,56 @@
1
1
  {
2
2
  "name": "@jgarber/eslint-config",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Shareable ESLint configuration.",
5
5
  "keywords": [
6
+ "config",
7
+ "configuration",
8
+ "eslint-config",
6
9
  "eslint",
7
10
  "eslintconfig",
8
- "eleventy",
9
- "javascript"
11
+ "javascript",
12
+ "lint"
10
13
  ],
11
14
  "homepage": "https://github.com/jgarber623/eslint-config",
12
15
  "bugs": "https://github.com/jgarber623/eslint-config/issues",
13
16
  "license": "MIT",
14
17
  "author": "Jason Garber <jason@sixtwothree.org> (https://sixtwothree.org)",
15
- "main": "index.js",
18
+ "files": [
19
+ "lib/*"
20
+ ],
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": "./lib/index.js",
24
+ "./ava": "./lib/ava.js",
25
+ "./commonjs": "./lib/commonjs.js"
26
+ },
16
27
  "repository": "github:jgarber623/eslint-config",
17
28
  "scripts": {
18
29
  "lint": "eslint .",
19
- "test": "jasmine"
30
+ "test": "c8 ava"
20
31
  },
21
32
  "engines": {
22
- "node": ">=16.0.0"
33
+ "node": ">=18.0.0"
23
34
  },
24
- "devDependencies": {
25
- "eslint": "^8.43.0",
35
+ "dependencies": {
36
+ "@eslint/js": "^8.50.0",
26
37
  "eslint-config-standard": "^17.1.0",
27
- "globals": "^13.20.0",
28
- "jasmine": "^5.0.2"
38
+ "eslint-plugin-ava": "^14.0.0",
39
+ "eslint-plugin-array-func": "^4.0.0",
40
+ "eslint-plugin-jsdoc": "^46.8.2",
41
+ "eslint-plugin-n": "^16.1.0",
42
+ "eslint-plugin-promise": "^6.1.1",
43
+ "eslint-plugin-regexp": "^1.15.0",
44
+ "eslint-plugin-sort-class-members": "^1.19.0",
45
+ "eslint-plugin-unicorn": "^48.0.1"
46
+ },
47
+ "devDependencies": {
48
+ "ava": "^5.3.1",
49
+ "c8": "^8.0.1",
50
+ "eslint": "^8.50.0"
29
51
  },
30
52
  "peerDependencies": {
31
- "eslint": ">=8.43.0",
32
- "eslint-config-standard": ">=17.1.0",
33
- "globals": ">=13.20.0"
53
+ "eslint": ">=8.50.0"
34
54
  },
35
55
  "publishConfig": {
36
56
  "access": "public"
package/.editorconfig DELETED
@@ -1,10 +0,0 @@
1
- # EditorConfig is awesome: https://EditorConfig.org
2
- root = true
3
-
4
- [*]
5
- charset = utf-8
6
- end_of_line = lf
7
- insert_final_newline = true
8
- indent_size = 2
9
- indent_style = space
10
- trim_trailing_whitespace = true
@@ -1,15 +0,0 @@
1
- version: 2
2
-
3
- updates:
4
- - package-ecosystem: "github-actions"
5
- directory: "/"
6
- schedule:
7
- interval: "weekly"
8
- assignees:
9
- - "jgarber623"
10
- - package-ecosystem: "npm"
11
- directory: "/"
12
- schedule:
13
- interval: "monthly"
14
- assignees:
15
- - "jgarber623"
@@ -1,27 +0,0 @@
1
- name: CI
2
-
3
- on: push
4
-
5
- jobs:
6
- lint:
7
- name: Lint files
8
- runs-on: ubuntu-20.04
9
- steps:
10
- - uses: actions/checkout@v3
11
- - uses: actions/setup-node@v3
12
- with:
13
- node-version-file: ".nvmrc"
14
- cache: npm
15
- - run: npm ci
16
- - run: npm run lint
17
- test:
18
- name: Test files
19
- runs-on: ubuntu-20.04
20
- steps:
21
- - uses: actions/checkout@v3
22
- - uses: actions/setup-node@v3
23
- with:
24
- node-version-file: ".nvmrc"
25
- cache: npm
26
- - run: npm ci
27
- - run: npm test
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- lts/*
package/eslint.config.js DELETED
@@ -1,15 +0,0 @@
1
- const globals = require('globals');
2
-
3
- const config = require('./index');
4
-
5
- module.exports = [
6
- ...config,
7
- {
8
- files: ['spec/**/*[sS]pec.?(m)js'],
9
- languageOptions: {
10
- globals: {
11
- ...globals.jasmine
12
- }
13
- }
14
- }
15
- ];
package/index.js DELETED
@@ -1,59 +0,0 @@
1
- /*
2
- * Import global identifiers from different JavaScript environments.
3
- *
4
- * @see {@link https://www.npmjs.com/package/globals}
5
- * @see {@link https://github.com/sindresorhus/globals/blob/HEAD/globals.json}
6
- */
7
- const globals = require('globals');
8
-
9
- /*
10
- * Import Standard's ESLint configurtation for use with ESLint's new "flat"
11
- * configuration file format.
12
- *
13
- * @see {@link https://github.com/standard/eslint-config-standard/blob/master/.eslintrc.json}
14
- * @see {@link https://eslint.org/docs/latest/use/configure/configuration-files-new}
15
- */
16
- const standard = require('eslint-config-standard');
17
-
18
- module.exports = [
19
- {
20
- plugins: Object.fromEntries(standard.plugins.map(plugin => [plugin, require(`eslint-plugin-${plugin}`)])),
21
- rules: {
22
- ...standard.rules,
23
-
24
- /*
25
- * Enforces consistent use of semicolons.
26
- *
27
- * @see {@link https://eslint.org/docs/latest/rules/semi}
28
- */
29
- semi: ['error', 'always'],
30
-
31
- /*
32
- * Enforces consistent spacing before function parentheses and will warn
33
- * whenever whitespace doesn't match the preferences specified.
34
- *
35
- * @see {@link https://eslint.org/docs/latest/rules/space-before-function-paren}
36
- */
37
- 'space-before-function-paren': ['error', {
38
- anonymous: 'never',
39
- asyncArrow: 'always',
40
- named: 'never'
41
- }]
42
- }
43
- },
44
- {
45
- /*
46
- * By default, ESLint's "flat" config considers `*.js` files as ECMAScript
47
- * modules (ESM). Instead, consider `*.js` files to be CommonJS modules.
48
- *
49
- * @see {@link https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects}
50
- */
51
- files: ['**/*.js'],
52
- languageOptions: {
53
- globals: {
54
- ...globals.commonjs
55
- },
56
- sourceType: 'commonjs'
57
- }
58
- }
59
- ];
package/spec/indexSpec.js DELETED
@@ -1,24 +0,0 @@
1
- const { FlatESLint } = require('eslint/use-at-your-own-risk');
2
-
3
- const config = require('../index');
4
-
5
- it('exports an Array', () => {
6
- expect(Array.isArray(config)).toBe(true);
7
- });
8
-
9
- it('loads the config and validates correct syntax', async () => {
10
- const eslint = new FlatESLint({ baseConfig: config });
11
- const [results] = await eslint.lintText(';\n');
12
-
13
- expect(results.errorCount).toEqual(0);
14
- });
15
-
16
- it('loads the config and invalidates incorrect syntax', async () => {
17
- const eslint = new FlatESLint({ baseConfig: config });
18
- const [results] = await eslint.lintText('(() => {}) ()\n');
19
-
20
- const ruleIds = results.messages.map(({ ruleId }) => ruleId);
21
-
22
- expect(results.errorCount).toEqual(2);
23
- expect(ruleIds).toEqual(jasmine.arrayContaining(['func-call-spacing', 'semi']));
24
- });
@@ -1,14 +0,0 @@
1
- {
2
- "spec_dir": "spec",
3
- "spec_files": [
4
- "**/*[sS]pec.?(m)js"
5
- ],
6
- "helpers": [
7
- "helpers/**/*.?(m)js"
8
- ],
9
- "env": {
10
- "failSpecWithNoExpectations": true,
11
- "random": true,
12
- "stopSpecOnExpectationFailure": false
13
- }
14
- }