Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce flat config #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 84 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ module.exports = {
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
module.exports = [
...algolia,
];
```

**package.json**
```json
{
Expand Down Expand Up @@ -86,6 +94,16 @@ module.exports = {
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
const algoliaJest = require('eslint-config-algolia/flat/jest');
module.exports = [
...algolia,
...algoliaJest,
];
```

**package.json**
```json
{
Expand All @@ -111,6 +129,16 @@ module.exports = {
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
const algoliaReact = require('eslint-config-algolia/flat/react');
module.exports = [
...algolia,
...algoliaReact,
];
```

**package.json**
```json
{
Expand All @@ -122,7 +150,7 @@ module.exports = {
}
```

### Flow
### Flow (deprecated)

**terminal**
```sh
Expand All @@ -136,7 +164,7 @@ module.exports = {
};
```

### Flow with React
### Flow with React (deprecated)

**terminal**
```sh
Expand Down Expand Up @@ -171,14 +199,31 @@ yarn add @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript -
**.eslintrc.js**
```js
module.exports = {
extends: ['algolia', 'algolia/typescript']
extends: ['algolia', 'algolia/typescript'],

parserOptions: {
project: '<path-to-tsconfig.json>',
},
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
const algoliaTypescript = require('eslint-config-algolia/flat/typescript');
module.exports = [
...algolia,
...algoliaTypescript,
{
languageOptions: {
parserOptions: {
project: '<path-to-tsconfig.json>',
},
},
},
];
```

**package.json**
```json
{
Expand Down Expand Up @@ -207,6 +252,18 @@ module.exports = {
```
**Note**: Be sure to put the `algolia/typescript` configuration last so the parser is properly set for TypeScript files.

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
const algoliaReact = require('eslint-config-algolia/flat/react');
const algoliaTypescript = require('eslint-config-algolia/flat/typescript');
module.exports = [
...algolia,
...algoliaReact,
...algoliaTypescript,
];
```

**package.json**
```json
{
Expand All @@ -233,6 +290,16 @@ module.exports = {
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
const algoliaVue = require('eslint-config-algolia/flat/vue');
module.exports = [
...algolia,
...algoliaVue,
];
```

**package.json**
```json
{
Expand Down Expand Up @@ -275,10 +342,23 @@ module.exports = {
extends: 'algolia',
rules: {
'import/no-commonjs': 'off'
}
},
};
```

**eslint.config.js**
```js
const algolia = require('eslint-config-algolia/flat/base');
module.exports = [
...algolia,
{
rules: {
'import/no-commonjs': 'off'
}
},
];
```

## Existing codebase setup

If you have a lot of files already written and wants to now use
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-config-algolia/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/eslint-config-algolia/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable import/no-commonjs */
const base = require('./flat/base');

module.exports = [...base];
61 changes: 61 additions & 0 deletions packages/eslint-config-algolia/flat/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable import/no-commonjs */
const eslintJs = require('@eslint/js');
const commentsPlugin = require('@eslint-community/eslint-plugin-eslint-comments');
const stylisticPlugin = require('@stylistic/eslint-plugin');
const importPlugin = require('eslint-plugin-import');
const jsdocPlugin = require('eslint-plugin-jsdoc');
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const globals = require('globals');

const rules = require('../rules/base');

// Remove legacy properties
delete rules.overrides;

module.exports = [
eslintJs.configs.recommended,
rules,
// prettier is set after to override our own rules
eslintPluginPrettierRecommended,
{
plugins: {
'@stylistic': stylisticPlugin,
'@eslint-community/eslint-comments': commentsPlugin,
import: importPlugin,
jsdoc: jsdocPlugin,
'react-hooks': reactHooksPlugin,
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true,
impliedStrict: true,
},
},
},
settings: {
'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],

'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
},
// Mixed codebase issues
{
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'jsdoc/no-types': ['error'],
},
},
];
18 changes: 18 additions & 0 deletions packages/eslint-config-algolia/flat/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable import/no-commonjs */
const jestPlugin = require('eslint-plugin-jest');
const globals = require('globals');

const jestRules = require('../rules/jest');

module.exports = [
jestRules,
{
...jestPlugin.configs['flat/recommended'],
...jestPlugin.configs['flat/style'],
languageOptions: {
globals: {
...globals.jest,
},
},
},
];
28 changes: 28 additions & 0 deletions packages/eslint-config-algolia/flat/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable import/no-commonjs */
const babelParser = require('@babel/eslint-parser');
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y');
const reactPlugin = require('eslint-plugin-react');
const reactHooksPlugin = require('eslint-plugin-react-hooks');

const rules = require('../rules/react');

module.exports = [
reactPlugin.configs.flat.recommended,
{
plugins: {
'react-hooks': reactHooksPlugin,
'jsx-a11y': jsxA11yPlugin,
},

languageOptions: {
parser: babelParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
requireConfigFile: false,
},
},
},
rules,
];
48 changes: 48 additions & 0 deletions packages/eslint-config-algolia/flat/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable import/no-commonjs */
const typescriptPlugin = require('@typescript-eslint/eslint-plugin');
const parser = require('@typescript-eslint/parser');
const importPlugin = require('eslint-plugin-import');

const rules = require('../rules/typescript');

// Remove legacy properties
delete rules.plugins;
delete rules.overrides;

module.exports = [
rules,
{
plugins: {
'@typescript-eslint': typescriptPlugin,
import: importPlugin,
},
languageOptions: {
parser,
parserOptions: {
ecmaFeatures: {
impliedStrict: true,
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
requireConfigFile: false,
},
},
},
// Mixed codebase issues
{
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowHigherOrderFunctions: true,
allowTypedFunctionExpressions: true,
// allowExpressions: true,
},
],
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
},
},
];
40 changes: 40 additions & 0 deletions packages/eslint-config-algolia/flat/vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// We don't extends from the `base` preset because the Vue plugin needs
// to use the parser under `parserOptions`. By doing this we broke the import
// plugin in the `react` preset. For now we just recreate the same configuration
// until all the plugins behave the same.

/* eslint-disable import/no-commonjs */
const babelParser = require('@babel/eslint-parser');
const importPlugin = require('eslint-plugin-import');
const vuePlugin = require('eslint-plugin-vue');
const globals = require('globals');

const rules = require('../rules/vue');

module.exports.flat = [
...vuePlugin.configs['flat/recommended'],
rules,
{
plugins: {
import: importPlugin,
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 2018,
sourceType: 'module',
parser: babelParser, // allows both flowtype and static class properties
parserOptions: {
ecmaFeatures: {
impliedStrict: true,
jsx: true,
},
},
},
settings: {
'import/extensions': ['.js'],
},
},
];
2 changes: 2 additions & 0 deletions packages/eslint-config-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@babel/core": "7.25.2",
"@babel/eslint-parser": "7.25.1",
"@eslint-community/eslint-plugin-eslint-comments": "4.4.0",
"@eslint/js": "9.11.1",
"@stylistic/eslint-plugin": "2.7.2",
"eslint": "8.57.0",
"eslint-config-prettier": "8.10.0",
Expand All @@ -37,6 +38,7 @@
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.35.0",
"eslint-plugin-react-hooks": "4.6.2",
"globals": "15.10.0",
"prettier": "3.3.3"
},
"peerDependencies": {
Expand Down
Loading