Skip to content

Commit

Permalink
feat!: Add more plugins (#19)
Browse files Browse the repository at this point in the history
* Add eslint-plugin-array-func package

* Configure eslint-plugin-array-func

* Add more ESLint plugins

* Add glue-y flat config compat code for plugins

* Configure more ESLint plugins

* Configure sort-keys rule

* Fix object key sorting in test files

* Add and configure eslint-plugin-regexp package

* Remove @eslint/eslintrc

* Add @eslint/js package and update config, tests

* Add and configure eslint-plugin-unicorn

* Ditch JSDOC comments in this project

* Add and configure sort-class-members plugin

* Ignore coverage folder

* Remove JSDOC-style comments

* Remove (for now) eslint-plugin-import

It's got some in-the-weeds issues with passing around data internally
that makes the plugin incompatible with flat config:

- import-js/eslint-plugin-import#2556
- import-js/eslint-plugin-import#2829
  • Loading branch information
jgarber623 authored Oct 5, 2023
1 parent 004b1c4 commit 445f87c
Show file tree
Hide file tree
Showing 14 changed files with 943 additions and 146 deletions.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @see {@link https://nodejs.org/dist/latest-v18.x/docs/api/packages.html#self-referencing-a-package-using-its-name}
*/
module.exports = [
{
ignores: ['coverage']
},
...(require('@jgarber/eslint-config/commonjs')),
...(require('@jgarber/eslint-config')),
...(require('@jgarber/eslint-config/ava'))
Expand Down
8 changes: 3 additions & 5 deletions lib/ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ const ava = require('eslint-plugin-ava');

module.exports = [
{
/**
* Use AVA's default file-matching patterns.
*
* @see {@link https://github.com/avajs/ava/blob/HEAD/docs/05-command-line.md}
*/
// Use AVA's default file-matching patterns.
//
// https://github.com/avajs/ava/blob/HEAD/docs/05-command-line.md
files: [
'test.js',
'src/test.js',
Expand Down
30 changes: 13 additions & 17 deletions lib/commonjs.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/**
* By default, ESLint's "flat" config considers `*.js` files to be ECMAScript
* modules (ESM). `*.mjs` files are always parsed as ESM modules and `*.cjs`
* files are always parsed as CommonJS modules.
*
* This configures ESLint to treat `*.js` files as CommonJS modules.
*
* Authors may also specify the module type in `package.json` using either
* `"type": "commonjs"` or `"type": "module"`.
*
* @see {@link https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects}
* @see {@link https://nodejs.org/dist/latest-v18.x/docs/api/modules.html#enabling}
*/
// By default, ESLint's "flat" config considers `*.js` files to be ECMAScript
// modules (ESM). `*.mjs` files are always parsed as ESM modules and `*.cjs`
// files are always parsed as CommonJS modules.
//
// This configures ESLint to treat `*.js` files as CommonJS modules.
//
// Authors may also specify the module type in `package.json` using either
// `"type": "commonjs"` or `"type": "module"`.
//
// https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-objects
// https://nodejs.org/dist/latest-v18.x/docs/api/modules.html#enabling
module.exports = [
{
files: ['**/*.js'],
languageOptions: {
/**
* @see {@link https://www.npmjs.com/package/globals}
* @see {@link https://github.com/sindresorhus/globals/blob/HEAD/globals.json}
*/
// https://www.npmjs.com/package/globals
// https://github.com/sindresorhus/globals/blob/HEAD/globals.json
globals: {
__dirname: 'readonly',
__filename: 'readonly',
Expand Down
21 changes: 21 additions & 0 deletions lib/compat/eslint-plugin-array-func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const plugin = require('eslint-plugin-array-func');
const { configs, rules } = plugin;

module.exports = {
configs: {
'flat/all': {
plugins: { 'array-func': plugin },
rules: {
...configs.recommended.rules,
...configs.all.rules
}
},
'flat/recommended': {
plugins: { 'array-func': plugin },
rules: {
...configs.recommended.rules
}
}
},
rules
};
12 changes: 12 additions & 0 deletions lib/compat/eslint-plugin-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const plugin = require('eslint-plugin-promise');
const { configs, rules } = plugin;

module.exports = {
configs: {
'flat/recommended': {
plugins: { promise: plugin },
rules: configs.recommended.rules
}
},
rules
};
16 changes: 16 additions & 0 deletions lib/compat/eslint-plugin-regexp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const plugin = require('eslint-plugin-regexp');
const { configs, rules } = plugin;

module.exports = {
configs: {
'flat/all': {
plugins: { regexp: plugin },
rules: configs.all.rules
},
'flat/recommended': {
plugins: { regexp: plugin },
rules: configs.recommended.rules
}
},
rules
};
12 changes: 12 additions & 0 deletions lib/compat/eslint-plugin-sort-class-members.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const plugin = require('eslint-plugin-sort-class-members');
const { configs, rules } = plugin;

module.exports = {
configs: {
'flat/recommended': {
plugins: { 'sort-class-members': plugin },
rules: configs.recommended.rules
}
},
rules
};
16 changes: 16 additions & 0 deletions lib/compat/eslint-plugin-unicorn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const plugin = require('eslint-plugin-unicorn');
const { configs, rules } = plugin;

module.exports = {
configs: {
'flat/all': {
plugins: { unicorn: plugin },
rules: configs.all.rules
},
'flat/recommended': {
plugins: { unicorn: plugin },
rules: configs.recommended.rules
}
},
rules
};
5 changes: 5 additions & 0 deletions lib/compat/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports.arrayFunc = require('./eslint-plugin-array-func');
module.exports.promise = require('./eslint-plugin-promise');
module.exports.regexp = require('./eslint-plugin-regexp');
module.exports.sortClassMembers = require('./eslint-plugin-sort-class-members');
module.exports.unicorn = require('./eslint-plugin-unicorn');
114 changes: 74 additions & 40 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,88 @@
const { FlatCompat } = require('@eslint/eslintrc');
// ESLint shared configurations
const js = require('@eslint/js');
const standard = require('eslint-config-standard');

const compat = new FlatCompat({
baseDirectory: __dirname
});
// ESLint plugins
const jsdoc = require('eslint-plugin-jsdoc');
const n = require('eslint-plugin-n');

// Compat module for non-"flat"-compatible plugins
const compat = require('./compat');

module.exports = [
/**
* eslint-config-standard doesn't (yet) provide a "flat" ESLint configuration.
* Until an updated version is released, use `FlatCompat` to provide a "flat"-
* compatible configuration object.
*
* @see {@link https://www.npmjs.com/package/eslint-config-standard}
*/
...compat.config((() => {
const { plugins, rules } = require('eslint-config-standard');

return {
extends: [
'plugin:import/recommended',
'plugin:n/recommended',
'plugin:promise/recommended'
],
plugins,
rules
};
})()),

/**
* Additional configuration to suite my taste.
*/
// https://www.npmjs.com/package/eslint-plugin-jsdoc
jsdoc.configs['flat/recommended-error'],

// https://www.npmjs.com/package/eslint-plugin-n
n.configs['flat/recommended'],

// https://www.npmjs.com/package/eslint-plugin-array-func
compat.arrayFunc.configs['flat/all'],

// https://www.npmjs.com/package/eslint-plugin-promise
compat.promise.configs['flat/recommended'],

// https://www.npmjs.com/package/eslint-plugin-regexp
compat.regexp.configs['flat/recommended'],

// https://www.npmjs.com/package/eslint-plugin-sort-class-members
compat.sortClassMembers.configs['flat/recommended'],

// https://www.npmjs.com/package/eslint-plugin-unicorn
compat.unicorn.configs['flat/recommended'],

{
rules: {
/**
* Enforces consistent use of semicolons.
*
* @see {@link https://eslint.org/docs/latest/rules/semi}
*/
// https://www.npmjs.com/package/@eslint/js
...js.configs.recommended.rules,

// https://www.npmjs.com/package/eslint-config-standard
//
// Remove eslint-plugin-import rules until the following "flat" config-
// related issues are resolved.
//
// https://github.com/import-js/eslint-plugin-import/issues/2556
// https://github.com/import-js/eslint-plugin-import/pull/2829
...Object.fromEntries(
Object.entries(standard.rules).filter(([key]) => {
return !key.startsWith('import/');
})
),

// https://eslint.org/docs/latest/rules/semi
semi: ['error', 'always'],

/**
* Enforces consistent spacing before function parentheses and will warn
* whenever whitespace doesn't match the preferences specified.
*
* @see {@link https://eslint.org/docs/latest/rules/space-before-function-paren}
*/
// https://eslint.org/docs/latest/rules/sort-keys
'sort-keys': ['error', 'asc', {
allowLineSeparatedGroups: true,
natural: true
}],

// https://eslint.org/docs/latest/rules/space-before-function-paren
'space-before-function-paren': ['error', {
anonymous: 'never',
asyncArrow: 'always',
named: 'never'
}]
}],

// Disable rules conflicting with eslint-plugin-unicorn.
//
// https://www.npmjs.com/package/eslint-plugin-array-func
'array-func/prefer-flat': 'off',
'array-func/prefer-flat-map': 'off',

// https://github.com/gajus/eslint-plugin-jsdoc/blob/HEAD/docs/rules/tag-lines.md
'jsdoc/tag-lines': ['error', 'any', { startLines: 1 }],

// ¯\_(ツ)_/¯
//
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/no-null.md}
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-module.md}
'unicorn/no-null': 'off',
'unicorn/prefer-module': 'off',

// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prevent-abbreviations.md
'unicorn/prevent-abbreviations': ['warn', { checkFilenames: false }]
}
}
];
Loading

0 comments on commit 445f87c

Please sign in to comment.