Skip to content

Commit

Permalink
feat: correct eslint9 implementation, add config generator
Browse files Browse the repository at this point in the history
  • Loading branch information
stabback committed Oct 29, 2024
1 parent 1083454 commit 55be7a3
Show file tree
Hide file tree
Showing 20 changed files with 6,998 additions and 8,186 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock.json
node_modules
File renamed without changes.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,51 @@ This plugin requires ESLint 9 or later.

You can use this plugin with pre-set configurations, or you can configure it yourself.

### Pre-set Configurations
### Generate a config

#### Node & Mocha
This is the recommended way to generate a configuration.

```js
const eslintPlugin6river = require('eslint-plugin-6river');
import eslintPluginSixriver from 'eslint-plugin-6river';

module.exports = [...eslintPlugin6river.configs['node-mocha']];
export default [...eslintPluginSixriver.generateConfig(import.meta.dirname, ['node', 'mocha'])];
```
#### Browser & Jest
Supported config names can be found in the generate-config.js file.
### Pre-set Configurations
#### TypeScript
This is the base opinionated TS configuration that you probably don't need to use by yourself. Use
one of the ecosystem versions below which extend this config.
```js
const eslintPlugin6river = require('eslint-plugin-6river');
import eslintPlugin6river from 'eslint-plugin-6river';

module.exports = [...eslintPlugin6river.configs['browser-jest']];
export default [...eslintPlugin6river.configs['typescript']];
```
### Custom Configuration
```js
const eslintPlugin6river = require('eslint-plugin-6river');
import eslintPlugin6river from 'eslint-plugin-6river';

module.exports = [
export default [
{
files: ['**/*.{ts,tsx}'],
plugins: {
'6river': eslintPlugin6river,
},
rules: {
'6river/rule-name': 'error',
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
];
```
Expand Down
14 changes: 0 additions & 14 deletions lib/configs/browser-jest.js

This file was deleted.

13 changes: 13 additions & 0 deletions lib/configs/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import plugin from 'eslint-plugin-jest';
import globals from 'globals';

export default [
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
globals: {
...globals.browser,
},
},
},
];
26 changes: 0 additions & 26 deletions lib/configs/common-rules.js

This file was deleted.

26 changes: 26 additions & 0 deletions lib/configs/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import globals from 'globals';

import eslintPluginJest from 'eslint-plugin-jest';

export default [
eslintPluginJest.configs['flat/recommended'],
{
rules: {
'jest/valid-title': ['error', { ignoreTypeOfDescribeName: true }],
},
files: ['**/*.{ts,tsx}'],
languageOptions: {
globals: {
...globals.jest,
},
},
},
{
files: ['**/jest.config.js'],
languageOptions: {
globals: {
...globals.node,
},
},
},
];
15 changes: 15 additions & 0 deletions lib/configs/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import globals from 'globals';

import eslintPluginMocha from 'eslint-plugin-mocha';

export default [
eslintPluginMocha.configs.flat.recommended,
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
globals: {
...globals.mocha,
},
},
},
];
17 changes: 0 additions & 17 deletions lib/configs/node-mocha.js

This file was deleted.

12 changes: 12 additions & 0 deletions lib/configs/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from 'globals';

export default [
{
files: ['**/*.ts'],
languageOptions: {
globals: {
...globals.node,
},
},
},
];
43 changes: 43 additions & 0 deletions lib/configs/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import eslintPluginReact from 'eslint-plugin-react';
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';

export default [
{
...eslintPluginReact.configs.flat.recommended,
settings: {
...eslintPluginReact.configs.flat.recommended?.settings,
react: {
...eslintPluginReact.configs.flat.recommended?.settings?.react,
version: 'detect',
},
},
},

// https://github.com/facebook/react/issues/28313
// While waiting for eslint-plugin-react-hooks to support eslint9, manually configure it.
// If you're reading this in 2025 or later, you probably can delete this and just use
// the predefined flat config once this is merged and release:
// https://github.com/facebook/react/pull/30774
{
files: ['**/*.{ts,tsx}'],
plugins: {
'react-hooks': eslintPluginReactHooks,
},
rules: eslintPluginReactHooks.configs.recommended.rules,
},
// General react config
{
files: ['**/*.{ts,tsx}'],
rules: {
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
},
files: ['**/*.{ts,tsx}'],
languageOptions: {
globals: {
React: 'readonly',
JSX: 'readonly',
},
},
},
];
122 changes: 122 additions & 0 deletions lib/configs/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import eslintPluginImport from 'eslint-plugin-import';
import js from '@eslint/js';
import ts from 'typescript-eslint';
import globals from 'globals';

import plugin from '../plugin.js';

const sixriverJsRules = {
// prettier owns most formatting rules now
'max-len': ['warn', 120, 2],

curly: ['error', 'all'],
'prefer-const': ['error'],
'no-console': ['error'],
'no-fallthrough': ['error'],
'no-undef': ['error'],
'no-var': ['error'],
strict: ['error', 'global'],
'object-shorthand': 'error',
'no-await-in-loop': 'error',
eqeqeq: 'error',
'require-jsdoc': 'off',
'import/order': [
'error',
{
groups: [['builtin'], ['external'], ['internal', 'parent', 'sibling', 'index']],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
},
],
'import/no-self-import': 'error',
'import/newline-after-import': 'error',
};

export default [
// Global ignore list, must only have this key
// https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
{
ignores: [
'.rush',
'dist*/',
'node_modules',
'coverage/',
'.prettierrc.js',
'eslint.config.mjs',
],
},

// Typescript gives an array of rules, because why not
...ts.configs.recommended,

// Our rules, customize 6River stuff here
{
name: 'eslint-plugin-6river-typescript',
files: ['**/*.{ts,tsx}'],
plugins: {
'6river': plugin,
import: eslintPluginImport,
},
rules: {
...sixriverJsRules,
'@typescript-eslint/no-empty-object-type': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
caughtErrors: 'none',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/triple-slash-reference': 'error',
'6river/new-cap': ['error', { capIsNewExceptionPattern: '^@' }],
'new-cap': 'off',
'no-cond-assign': [2, 'always'],
'no-undef': 'off',
'no-unused-vars': 'off',
'valid-jsdoc': 'off',
'no-invalid-this': 'off',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
linterOptions: {
noInlineConfig: false,
reportUnusedDisableDirectives: 'warn',
},
},

{
name: 'eslint-plugin-6river-javascript',
files: ['**/*.{js,jsx,mjs,cjs}'],
plugins: {
'6river': plugin,
import: eslintPluginImport,
},
rules: {
...js.configs.recommended.rules,
...sixriverJsRules,
},
},

// Config file overrides
{
files: ['.prettierrc.js'],
languageOptions: {
globals: {
...globals.node,
},
},
},
];
Loading

0 comments on commit 55be7a3

Please sign in to comment.