Skip to content

Commit

Permalink
INCOMPLETE: waiting on:
Browse files Browse the repository at this point in the history
1. eslint-plugin-import
2. ideally, eslint-plugin-escompat when eslint 9 version ready
3. ideally, eslint-plugin-unsanitized (waiting on typescript-eslint))
4. ideally, @fintechstudios/eslint-plugin-chai-as-promised
5. ideally, eslint-plugin-mocha-cleanup

feat: switch to flat config

BREAKING CHANGE:

Requires Node 18.20.3+

Also:
- chore: update globals, semver
- chore: some TS work
- feat: detects sourceType automatically for .js files too, based on `package.json`
- fix: drop no-unpublished-import checks from rc configs
- fix: add eslint.config.js to ESM configs
  • Loading branch information
brettz9 committed Jul 16, 2024
1 parent 337db0f commit c64699f
Show file tree
Hide file tree
Showing 126 changed files with 5,106 additions and 3,000 deletions.
72 changes: 38 additions & 34 deletions +babel.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
'use strict';

// Move to own repo so can have `@babel/eslint-parser` and `@babel/eslint-plugin` as deps.
// Move to own repo so can have `@babel/eslint-parser` and
// `@babel/eslint-plugin` as deps.
/* eslint-disable jsdoc/imports-as-dependencies -- Bug? */

// Adapted from MIT-licensed: https://github.com/futagoza/eslint-config-futagozaryuu/blob/master/packages/%40futagoza/eslint-config-core/stylistic-issues.js

// Types: https://github.com/babel/babel/issues/16221

import babelParser from '@babel/eslint-parser';
import babelEslintPlugin from '@babel/eslint-plugin';

/**
* Allows passing in a whole config to wrap.
* @param {ESLintConfig} config
* @returns {ESLintConfig}
* @param {import('eslint').Linter.FlatConfig} config
* @returns {import('eslint').Linter.FlatConfig}
*/
module.exports = function (config) {
export default function babelConfig (config) {
return {
parser: '@babel/eslint-parser',
parserOptions: {
...config.parserOptions,
requireConfigFile: false
languageOptions: {
parser: babelParser,
parserOptions: {
...config.languageOptions?.parserOptions,
requireConfigFile: false
}
},

plugins: [
plugins: {
...config.plugins,
'@babel/eslint-plugin'
],
babelEslintPlugin
},
rules: {

...config.rules,
Expand All @@ -39,47 +46,44 @@ module.exports = function (config) {
/**
* Require constructor names to begin with a capital letter.
*
* @see
* - https://eslint.org/docs/rules/new-cap
* - https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules
* @see {@link https://eslint.org/docs/rules/new-cap}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/new-cap': config.rules['new-cap'] || 'off',
'@babel/new-cap': config?.rules?.['new-cap'] || 'off',

/**
* Disallow `this` keywords outside of classes or class-like objects.
*
* @see
* - https://eslint.org/docs/rules/no-invalid-this
* - https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules
* @see {@link https://eslint.org/docs/rules/no-invalid-this}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/no-invalid-this': config.rules['no-invalid-this'] || 'off',
'@babel/no-invalid-this': config?.rules?.['no-invalid-this'] || 'off',

/**
* Disallow unused expressions.
*
* @see
* - https://eslint.org/docs/rules/no-unused-expressions
* - https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules
* @see {@link https://eslint.org/docs/rules/no-unused-expressions}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/no-unused-expressions': config.rules['no-unused-expressions'] || 'off',
'@babel/no-unused-expressions':
config?.rules?.['no-unused-expressions'] || 'off',

/**
* Enforce consistent spacing inside braces (🔧 ).
*
* @see
* - https://eslint.org/docs/rules/object-curly-spacing
* - https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules
* @see {@link https://eslint.org/docs/rules/object-curly-spacing}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/object-curly-spacing': config.rules['object-curly-spacing'] || 'off',
'@babel/object-curly-spacing':
config?.rules?.['object-curly-spacing'] || 'off',

/**
* Require or disallow semicolons instead of ASI (🔧).
*
* @see
* - https://eslint.org/docs/rules/semi
* - https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules
* @see {@link https://eslint.org/docs/rules/semi}
* @see {@link https://github.com/babel/babel/tree/master/eslint/babel-eslint-plugin#rules}
*/
'@babel/semi': config.rules.semi || 'off'
'@babel/semi': config?.rules?.semi || 'off'
}
};
};
}
33 changes: 18 additions & 15 deletions +modules.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

module.exports = {
parserOptions: {
ecmaFeatures: {globalReturn: false},
sourceType: 'module'
},
globals: {
__dirname: 'off',
__filename: 'off',
exports: 'off',
module: 'off',
require: 'off'
},
/* eslint-disable jsdoc/imports-as-dependencies -- Bug */
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [{
languageOptions: {
parserOptions: {
ecmaFeatures: {globalReturn: false}
},
sourceType: 'module',
globals: {
__dirname: 'off',
__filename: 'off',
exports: 'off',
module: 'off',
require: 'off'
}
}
}, {
rules: {
'n/no-unsupported-features/es-syntax': [
'error',
Expand All @@ -21,4 +24,4 @@ module.exports = {
{ignores: ['modules', 'dynamicImport']}
]
}
};
}];
40 changes: 21 additions & 19 deletions +script-node.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
'use strict';
/* eslint-disable jsdoc/imports-as-dependencies -- Bug */
import node from 'eslint-plugin-n';
import globals from 'globals';

// As adding after defaults, recalculate ecmaVersion (Node plugins sets own
// `ecmaVersion`)
const {env, ecmaVersion} = require('./detectEnv.js');
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
node.configs['flat/recommended-script'],
{
languageOptions: {
globals: globals.node,
parserOptions: {
ecmaFeatures: {
globalReturn: true
}
}
},
rules: {
// Allow for Node or Unicorn
'no-process-exit': 'off',

module.exports = {
env,
extends: ['plugin:n/recommended-script'],
parserOptions: {
ecmaVersion,
ecmaFeatures: {
globalReturn: true
'import/no-commonjs': 'off',
strict: ['error']
}
},
rules: {
// Allow for Node or Unicorn
'no-process-exit': 'off',

'import/no-commonjs': 'off',
strict: ['error']
}
};
];
16 changes: 9 additions & 7 deletions +script.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

module.exports = {
parserOptions: {
/* eslint-disable jsdoc/imports-as-dependencies -- Bug */
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [{
languageOptions: {
sourceType: 'script',
ecmaFeatures: {
globalReturn: false
parserOptions: {
ecmaFeatures: {
globalReturn: false
}
}
},
rules: {
'import/no-commonjs': 'off',
strict: ['error']
}
};
}];
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

32 changes: 0 additions & 32 deletions .eslintrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions .ncurc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
reject: [
// todo[engine:node@>=20]
'rimraf'
]
};
11 changes: 0 additions & 11 deletions .ncurc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pnpm-lock.yaml
eslint.config.js
inherited-rules/build.js
typings
44 changes: 13 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,19 @@ install-peerdeps -d eslint-config-ash-nazg

## The rules

See [index.js](./index.js) (and [node.js](./node.js) for `ash-nazg/node`
See [main.js](./main.js) (and [node.js](./node.js) for `ash-nazg/node`
rules) for the rules we explicitly include (and see
[sauron.js](./sauron.js) for the even stricter `ash-nazg/sauron` rules or
[great-eye](./great-eye.js) (or [great-eye-node](./great-eye-node.js)) for
still stricter rules though which are probably best not used).

`env` is set to automatically include `'shared-node-browser': true` given that
most environments will be Node or a browser or a polyglot Node-browser. If you
really don't want this, you can override by setting
`'shared-node-browser': false`. Note that this setting only adds globals which
are present in either Node or the browser; it won't falsely allow browser
globals in a Node app or vice versa; you can use `env`'s `node: true` or
`browser: true` if you want to support Node or browser globals.

(See [explicitly-unused.js](./explicitly-unused.js) for the core and extended
rules we don't include (rationale for non-inclusion below).)

- [Main rules](https://eslint.org/docs/rules/) (also search for "error" within `eslint-recommended.js` of `@eslint/js`) for the `eslint:recommended` rules we inherit (though see below for our two modifications to these).
- ["standard"](https://github.com/standard/eslint-config-standard/blob/master/eslintrc.json)
rules we inherit (though see below for our handful of modifications).
- [@brettz9/eslint-plugin](https://github.com/brettz9/eslint-plugin)
for a number of added rules
- [eslint-comments/recommended](https://github.com/mysticatea/eslint-plugin-eslint-comments)
- [eslint-comments/recommended](https://github.com/eslint-community/eslint-plugin-eslint-comments)
- [eslint-plugin-no-use-extend-native](https://github.com/dustinspecker/eslint-plugin-no-use-extend-native) for one added rule.
- [eslint-plugin-no-unsanitized](https://github.com/mozilla/eslint-plugin-no-unsanitized) for two added rules.
- [Recommended Unicorn rules](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/index.js#L20-L53) (a few items disabled and enabled as per below)
Expand Down Expand Up @@ -126,12 +116,12 @@ typically inheriting "recommended" configs), see
`/inherited-rules/implicitly-included`.

To see which rules from the extended config we disabled, see our relevant
config(s) (e.g., `index.js`).
config(s) (e.g., `main.js`).

To see which rules from the plugin that each extended config derives from
(i.e., the non-recommended rules of a plug-in), see `explicitly-unused.js`
for ones we have consciously not used and see our relevant config(s)
(e.g., `index.js`) for the ones we did add (alongside any recommended).
(e.g., `main.js`) for the ones we did add (alongside any recommended).

The `unused` folder is used to capture any (non-recommended) rules which
are not explicitly either enabled or within `explicitly-unused.js` (as
Expand Down Expand Up @@ -406,15 +396,15 @@ appears, to Dark Lords.

`promise/no-nesting` - can be useful to nest sometimes

`promise/no-promise-in-callback` - May be difficult to apply (Note: Is disabled in `index.js` but enabled in `sauron.js`)
`promise/no-promise-in-callback` - May be difficult to apply (Note: Is disabled in `main.js` but enabled in `sauron.js`)

`promise/no-callback-in-promise` - May be difficult to apply (Note: Is disabled in `index.js` but enabled in `sauron.js`)
`promise/no-callback-in-promise` - May be difficult to apply (Note: Is disabled in `main.js` but enabled in `sauron.js`)

`promise/avoid-new` - Can be useful or even necessary for APIs missing Promise version (Note: Is disabled in `index.js` but enabled in `sauron.js`; could use `promisify`)
`promise/avoid-new` - Can be useful or even necessary for APIs missing Promise version (Note: Is disabled in `main.js` but enabled in `sauron.js`; could use `promisify`)

`promise/no-return-in-finally` - (Note: Is disabled in `index.js` but enabled in `sauron.js`)
`promise/no-return-in-finally` - (Note: Is disabled in `main.js` but enabled in `sauron.js`)

`promise/valid-params` - (Note: Is disabled in `index.js` but enabled in `sauron.js`)
`promise/valid-params` - (Note: Is disabled in `main.js` but enabled in `sauron.js`)

#### Rationale for suppressing some `eslint-plugin-jsdoc` rules

Expand Down Expand Up @@ -537,18 +527,6 @@ appears, to Dark Lords.
- `eslint-comments/no-restricted-disable` - See no need
- `eslint-comments/no-use` - See no need

### Rationale for not including some `plugin:@brettz9/es6` rules

- `@brettz9/arrow-parens` - Covered by other rules
- `@brettz9/no-instanceof-array` - Covered by our blocking of all
`instanceof`
- `@brettz9/no-instanceof-wrapper` - Covered by our blocking of all
`instanceof`
- `@brettz9/prefer-for-of` - I prefer array extras for easier reuse,
currying, etc. than `for-of`
- `@brettz9/no-use-ignored-vars` - Relies on a regex (for pseudo-privates)
which can be useful

### Rationale for not including some `array-func` rules

- `array-func/prefer-array-from` - While it may benefit performance, it is
Expand Down Expand Up @@ -711,6 +689,10 @@ The `preferredTypes` setting was enabled here for integer/float as it can
be cumbersome for projects to distinguish and because `Promise` even
subclassed doesn't indicate the rejector type.

## Rationale for not including some rules in @brettz9/eslint-plugin

- `@brettz9/for-of` - Iterating functions can be easier to refactor

## Rationale for including rules that might not seem necessary

- `no-implicit-globals` - Included despite not applying to modules, in
Expand Down
11 changes: 11 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable jsdoc/imports-as-dependencies -- Bug */
import eslintCompat from 'eslint-plugin-compat';
// import esCompat from 'eslint-plugin-escompat'; // Todo: Waiting on https://github.com/keithamus/eslint-plugin-escompat/pull/24
// import noUnsanitized from 'eslint-plugin-no-unsanitized'; // Todo: Disable until https://github.com/mozilla/eslint-plugin-no-unsanitized/pull/239#issuecomment-2132867450

/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
eslintCompat.configs['flat/recommended']
// esCompat.configs['flat/recommended]
// noUnsanitized.DOM,
];
Loading

0 comments on commit c64699f

Please sign in to comment.