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

Feature/new-flat-config #1

Merged
merged 35 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
841aa08
Simplify package
osmestad Sep 7, 2023
65f0920
Initial rules extracted from current Web Player repo, converted to ne…
osmestad Sep 7, 2023
790c0e2
Initial TS config to allow using TS as ESLint parser
osmestad Sep 7, 2023
0cbdca5
Initial simplified docs
osmestad Sep 7, 2023
1b5983d
First draft test modernization
osmestad Sep 7, 2023
2a1a864
Drop Travis and update GH Action to Node LTS
osmestad Sep 7, 2023
23c6fe7
Update another Node 16 reference
osmestad Sep 7, 2023
fca5d22
Patch `eslint-plugin-typescript-sort-keys` for ESM compat.
osmestad Sep 7, 2023
03b1ce7
Switch to TS import resolution in linting
osmestad Sep 7, 2023
3a86faa
No longer needed, after resolution "fix"
osmestad Sep 7, 2023
70a8f8d
Add specific configs for:
osmestad Sep 7, 2023
58924bc
Enforce `.json` for imports
osmestad Sep 7, 2023
cb95e93
Move `no .only` tests to global scope, as it is a valid concern for u…
osmestad Sep 7, 2023
be291fe
Clean up some comments
osmestad Sep 7, 2023
1d9ab95
Document JS module missing types workaround
osmestad Sep 12, 2023
7b75e7e
Makes tests work again
osmestad Sep 12, 2023
bebf22f
Set a React version (latest) to avoid warning
osmestad Sep 12, 2023
1045acd
Inline Istanbul ignore reason rule
osmestad Sep 18, 2023
70c7322
Sort TS rules with the general rules
osmestad Sep 18, 2023
9f29be6
Add tests for sorting rules we use
osmestad Sep 18, 2023
b72138f
Update some packages
osmestad Sep 18, 2023
c3d1adf
Switch to Perfectionist for sorting
osmestad Sep 18, 2023
f8bd0ba
Update dependencies
osmestad Sep 19, 2023
da3c000
Split config in rule-set files
osmestad Sep 19, 2023
fd9d7af
Fix sorting according to new rules
osmestad Sep 19, 2023
0bfc20b
Ban TS comment should be an error
osmestad Sep 19, 2023
d81d020
Clean up some comments
osmestad Sep 19, 2023
e099369
Drop some packages no longer needed
osmestad Sep 19, 2023
0c7b9e0
Reenable confusingBrowserGlobals protection
osmestad Sep 19, 2023
d95cfc5
Enable JSX a11y plugin
osmestad Sep 19, 2023
79a3643
Document usage
osmestad Sep 19, 2023
b1c3cc2
Stricter TS config
osmestad Sep 19, 2023
cc2c6bf
Document `"type": "module"` workaround
osmestad Sep 20, 2023
abfe068
Add missing folder to "files"
osmestad Sep 20, 2023
503a83b
Update a comment
osmestad Sep 20, 2023
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
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

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

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"[javascript][typescript][typescriptreact][json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": false
"eslint.experimental.useFlatConfig": true
}
71 changes: 48 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,70 @@
# eslint-config-tidal

[![Build Status](https://travis-ci.org/tidal-engineering/eslint-config-tidal.svg?branch=master)](https://travis-ci.org/tidal-engineering/eslint-config-tidal)
[![Codacy grade](https://img.shields.io/codacy/grade/e20818172062471ebc0c1b69e5ea0887.svg 'Codacy grade')](https://www.codacy.com/app/karlsson/eslint-config-tidal)
[![NPM downloads](https://img.shields.io/npm/dm/eslint-config-tidal.svg 'NPM downloads')](https://www.npmjs.com/package/eslint-config-tidal)
[![NPM version](https://img.shields.io/npm/v/eslint-config-tidal.svg 'NPM version')](https://www.npmjs.com/package/eslint-config-tidal)
[![Node version](https://img.shields.io/node/v/eslint-config-tidal.svg 'Node version')](https://www.npmjs.com/package/eslint-config-tidal)
[![Dependency status](https://img.shields.io/david/tidal-engineering/eslint-config-tidal.svg 'Dependency status')](https://david-dm.org/tidal-engineering/eslint-config-tidal)

> ESLint [shareable config](http://eslint.org/docs/developer-guide/shareable-configs.html) for the TIDAL Code Style.

> ESLint [shareable config](http://eslint.org/docs/developer-guide/shareable-configs.html) for the TIDAL web frontend code style using the new [flat config format](https://eslint.org/docs/latest/use/configure/configuration-files-new).

## Usage

We export five ESLint configurations for your usage.
We export one ESLint configuration for your usage (including Prettier for formatting).

### eslint-config-tidal
Install the package as a `devDependency`: `@tidal-music/eslint-config-tidal` along with `eslint` (and possible any plugins/configs that should be project specific).

Our default export contains all of our base ESLint rules. It requires `eslint` and `eslint-plugin-import`.
Add a root `eslint.config.js` file, similar to this:

1. Install the correct versions (check `peerDependencies`) of each package:
```
import tidal from '@tidal-music/eslint-config-tidal';

/** @type { import("eslint").Linter.FlatConfig[] } */
export default [
...tidal,
{
files: ['*.js', '**/*.js', '**/*.ts', '**/*.tsx'],
},
{
ignores: [
'node_modules/*',
/* Build output folders, etc */
],
},
/* Add any overrides here */
];
```

```sh
npm install --save-dev eslint-config-tidal eslint-plugin-import
For running from a shell you can add an entry in `package.json`s `scripts` like this:
```
"lint:code": "eslint . --cache --cache-strategy content",
```
(which will also cache results, so re-runs are faster)

2. Add `"extends": "tidal"` to your `.eslintrc`.
This depends on your `package.json` including `"type": "module"`. If that is not possible, you can work around that by renaming your `eslint.config.js` to: `eslint.config.mjs` and launching it like this instead: `ESLINT_USE_FLAT_CONFIG=true eslint . --config eslint.config.mjs`.

### eslint-config-tidal/flow
### VSCode setup

This entry point enables the linting rules for Flow. To use, add `"extends": ["tidal", "tidal/flow"]` to your `.eslintrc`.
Additional required packages: `eslint-plugin-flowtype`.
Install the plugin: [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

And then ensure you have this in your workspace or user settings:
```
"[javascript][typescript][typescriptreact][json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.experimental.useFlatConfig": true
```
(This will auto-fix and auto format the files on save.)

### eslint-config-tidal/react
## Philosophy

This entry point enables the linting rules for React (requires v16.8+). To use, add `"extends": ["tidal", "tidal/react"]` to your `.eslintrc`.
Additional required packages: `eslint-plugin-react`, `eslint-plugin-react-hooks`, `eslint-plugin-jest`, `eslint-plugin-jsx-a11y`.
This package is pretty opinionated, if some rules are not suitable in your context they can be disable in your `eslint.config.js` or set to warnings instead of errors, if it makes sense to push for them eventually.

### eslint-config-tidal/typescript
In this package however rules should (ideally) either be "error" or "off".

This entry point enables the linting rules for Typescript. To use, add `"extends": ["tidal", "tidal/typescript", "plugin:import/typescript"]` to your `.eslintrc`.
Additional required packages: `@typescript-eslint/eslint-plugin`, `@typescript-eslint/parser`.

### eslint-config-tidal/legacy
## Development:

Lints ES5 and below. To use, add `"extends": ["tidal", "tidal/legacy"]` to your `.eslintrc`.
In the package you want to lint: (assuming it is in a sibling folder)
`yarn link ../eslint-config-tidal`
24 changes: 24 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import globals from 'globals';

import tidal from './index.js';

/** @type { import("eslint").Linter.FlatConfig[] } */
export default [
...tidal,
{
files: ['*.js', '**/*.js', '**/*.ts', '**/*.tsx'],
},
{
ignores: ['test/cases/*'],
},
{
languageOptions: {
globals: {
...globals.node,
},
},
settings: {
'import/internal-regex': '^@tidal/',
},
},
];
4 changes: 0 additions & 4 deletions flow.js

This file was deleted.

2 changes: 2 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is a workaround to allow importing any JS package without TS types
declare module '*';
54 changes: 37 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
module.exports = {
extends: [
'./rules/best-practices',
'./rules/errors',
'./rules/es6',
'./rules/imports',
'./rules/node',
'./rules/strict',
'./rules/variables',
'./rules/style',
].map(require.resolve),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {},
};
import path from 'path';
import { fileURLToPath } from 'url';

import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import perfectionistNatural from 'eslint-plugin-perfectionist/configs/recommended-natural';

import baseRuleSet from './rule-sets/base.js';
import cypressRuleSet from './rule-sets/cypress.js';
import dtsRuleSet from './rule-sets/dts.js';
import nodeRuleSet from './rule-sets/node.js';
import unitTestRuleSet from './rule-sets/unit-test.js';

// mimic CommonJS variables (in ESM)
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

/** @type { import("eslint").Linter.FlatConfig[] } */
export default [
js.configs.recommended,
compat.extends('eslint-config-xo/browser')[0],
compat.extends('eslint-config-xo-react')[0],
eslintConfigPrettier,
perfectionistNatural,
// Base Tidal rule set:
baseRuleSet,
// Following are some file type specific overrides:
cypressRuleSet,
dtsRuleSet,
nodeRuleSet,
unitTestRuleSet,
];
7 changes: 7 additions & 0 deletions internal-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { requireCoverageIgnoreReason } from './require-coverage-ignore-reason.js';

export default {
rules: {
'require-coverage-ignore-reason': requireCoverageIgnoreReason,
},
};
27 changes: 27 additions & 0 deletions internal-rules/require-coverage-ignore-reason.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
// Extracted from: https://github.com/graphql/graphql-js/pull/3388 related to:
// https://github.com/istanbuljs/eslint-plugin-istanbul/pull/17
// Fixed reason length check and converted to ESM.

export function requireCoverageIgnoreReason(context) {
const istanbulRegExp = /^\s*istanbul\s+ignore\s+(if|else|next|file)\s+/;
return {
Program() {
const sourceCode = context.getSourceCode();

for (const node of sourceCode.getAllComments()) {
const comment = node.value;

if (comment.match(istanbulRegExp)) {
const reason = comment.replace(istanbulRegExp, '');
if (reason.length === 0) {
context.report({
message: 'Add a reason why code coverage should be ignored',
node,
});
}
}
}
},
};
}
39 changes: 0 additions & 39 deletions legacy.js

This file was deleted.

Loading
Loading