Skip to content

Commit

Permalink
Eslint: use hermes-eslint parser (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml authored and kodiakhq[bot] committed Jul 15, 2022
1 parent eb1b656 commit 66e29f6
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 67 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
node_modules/

src/babel-preset-adeira/src/__tests__/__fixtures__
src/sx-tailwind-website/__github__/flow-typed

# https://github.com/prettier/prettier/issues/6102
**/__generated__/*.graphql.js
Expand Down
8 changes: 3 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ module.exports = {
jest: true,
node: true,
},
parser: '@babel/eslint-parser', // TODO: consider moving this into `eslint-config-adeira`
parser: 'hermes-eslint',
parserOptions: {
// https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/hermes-eslint/README.md
sourceType: 'module',
ecmaVersion: 2021,
ecmaFeatures: {
jsx: false,
},
fbt: true,
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"@adeira/monorepo-utils": "^0.11.0",
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/eslint-parser": "^7.18.2",
"babel-jest": "^28.1.3",
"babel-loader": "^8.2.5",
"eslint": "^8.19.0",
"eslint-formatter-codeframe": "^7.32.1",
"flow-bin": "^0.182.0",
"glob": "^8.0.3",
"hermes-eslint": "^0.9.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"prettier": "^2.7.1"
Expand Down
8 changes: 8 additions & 0 deletions src/eslint-config-adeira/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Unreleased

The Eslint Config now requires [`hermes-eslint`](https://www.npmjs.com/package/hermes-eslint) as an Eslint parser. Technically, the config works with any other parser (say `@babel/eslint-parser`) as well, however, some rules were adjusted for `hermes-eslint`. Notably:

- `no-undef` was turned off (not needed, especially in combination with Flow - superfluous rule)
- `ft-flow/define-flow-type` turned off (not needed with Hermes)
- `ft-flow/use-flow-type` turned off (not needed with Hermes)
- `react/jsx-uses-react` turned off (not needed with Hermes)
- `react/jsx-uses-vars` turned off (not needed with Hermes)

# 7.7.0

- New rule [`@next/next/no-styled-jsx-in-document`](https://nextjs.org/docs/messages/no-styled-jsx-in-document) enabled.
Expand Down
18 changes: 6 additions & 12 deletions src/eslint-config-adeira/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Purpose of this package is to share common eslint configuration among other JS projects. It should not be annoying but rather helpful when you understand _"why"_ of each rule (please give us feedback if you disagree with some rules).
Eslint config designed to work well for [Adeira](https://github.com/adeira) projects. It's especially powerful in combination with [Flow](https://flow.org/) and [`hermes-eslint`](https://www.npmjs.com/package/hermes-eslint).

# Usage

Expand All @@ -7,7 +7,7 @@ Before you start you should **remove all Eslint plugins and Prettier** from your
Install this package (as well as Eslint):

```
yarn add eslint @adeira/eslint-config --dev [--ignore-workspace-root-check]
yarn add eslint @adeira/eslint-config --dev
```

And use it in your `.eslintrc.js`:
Expand All @@ -24,9 +24,9 @@ module.exports = {
};
```

Strict version of the config turns _some_ warnings into errors. We use warnings as a migration strategy for the future breaking release but you can make the config more strict even today (so your CI will fail). Not all warnings are turned into errors - only the ones considered to be errors in the future version. Please be aware that strict mode is like living on the edge: minor upgrade can break your CI (while others will get only warnings). You will be ready for the future major version though.
Strict version of the config turns _some_ warnings into errors. We use warnings as a migration strategy for the future breaking release, however, you can make the config more strict even today (so your CI will fail). Not all warnings are turned into errors - only the ones considered to be errors in the future version. Please be aware that strict mode is like living on the edge: minor upgrade can break your CI (while others will get only warnings). You will be ready for the future major version though.

You can also set your eslint as needed with `@babel/eslint-parser` parser for example (you need to install it separately):
It's recommended using `hermes-eslint` parser with this config (you need to install it separately):

```js
const OFF = 0;
Expand All @@ -38,13 +38,9 @@ module.exports = {

extends: ['@adeira/eslint-config/strict'],

parser: '@babel/eslint-parser',
parser: 'hermes-eslint',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
ecmaFeatures: {
jsx: false,
},
},

env: {
Expand All @@ -55,9 +51,7 @@ module.exports = {
};
```

It is important to report any issues with the eslint configuration back so we can improve it **for everyone**. These rules should be related only to how we write JS code so it's perfectly fine if you have some additional rules closely related to your project (`no-restricted-imports` for example).

Also please note that **you should not ignore Eslint warnings**! These warnings are helping you to migrate to the future major version. Some of them will turn into errors in the next major version bump.
Please note that **you should not ignore Eslint warnings**! These warnings are helping you to migrate to the future major version. Some of them will turn into errors in the next major version bump.

# Config subsets

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum StatusDefault1 {
Off,
}

// eslint-disable-next-line no-unused-vars
enum StatusDefault2 of string {
Active,
Paused,
Expand All @@ -18,6 +19,7 @@ enum StatusString1 {
Off = 'off',
}

// eslint-disable-next-line no-unused-vars
enum StatusString2 of string {
Active = 'active',
Paused = 'paused',
Expand All @@ -30,12 +32,14 @@ enum StatusNumber1 {
Off = 3,
}

// eslint-disable-next-line no-unused-vars
enum StatusNumber2 of number {
Active = 1,
Paused = 2,
Off = 3,
}

// eslint-disable-next-line no-unused-vars
enum StatusBoolean1 {
Active = true,
Off = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Object {
1,
"boolean",
],
"ft-flow/define-flow-type": 1,
"ft-flow/define-flow-type": 0,
"ft-flow/delimiter-dangle": 0,
"ft-flow/enforce-line-break": 0,
"ft-flow/enforce-suppression-code": 2,
Expand Down Expand Up @@ -265,7 +265,7 @@ Object {
"ft-flow/type-id-match": 0,
"ft-flow/type-import-style": 0,
"ft-flow/union-intersection-spacing": 0,
"ft-flow/use-flow-type": 1,
"ft-flow/use-flow-type": 0,
"ft-flow/use-read-only-spread": 2,
"ft-flow/valid-syntax": 0,
"func-call-spacing": "off",
Expand Down Expand Up @@ -719,7 +719,7 @@ Object {
"no-this-before-super": 2,
"no-throw-literal": 1,
"no-trailing-spaces": "off",
"no-undef": 2,
"no-undef": 0,
"no-undef-init": 2,
"no-undefined": 0,
"no-underscore-dangle": 0,
Expand Down Expand Up @@ -915,8 +915,8 @@ Object {
"react/jsx-sort-props": 0,
"react/jsx-space-before-closing": "off",
"react/jsx-tag-spacing": "off",
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 2,
"react/jsx-uses-react": 0,
"react/jsx-uses-vars": 0,
"react/jsx-wrap-multilines": "off",
"react/no-access-state-in-setstate": 2,
"react/no-adjacent-inline-elements": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Object {
"no-ternary": 0,
"no-this-before-super": 2,
"no-throw-literal": 1,
"no-undef": 2,
"no-undef": 0,
"no-undef-init": 2,
"no-undefined": 0,
"no-underscore-dangle": 0,
Expand Down Expand Up @@ -616,7 +616,7 @@ Object {
1,
"boolean",
],
"ft-flow/define-flow-type": 1,
"ft-flow/define-flow-type": 0,
"ft-flow/delimiter-dangle": 0,
"ft-flow/enforce-line-break": 0,
"ft-flow/enforce-suppression-code": 2,
Expand Down Expand Up @@ -681,7 +681,7 @@ Object {
"ft-flow/type-id-match": 0,
"ft-flow/type-import-style": 0,
"ft-flow/union-intersection-spacing": 0,
"ft-flow/use-flow-type": 1,
"ft-flow/use-flow-type": 0,
"ft-flow/use-read-only-spread": 2,
"ft-flow/valid-syntax": 0,
"prettier/prettier": Array [
Expand Down Expand Up @@ -1050,8 +1050,8 @@ Object {
"react/jsx-props-no-spreading": 0,
"react/jsx-sort-default-props": 0,
"react/jsx-sort-props": 0,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 2,
"react/jsx-uses-react": 0,
"react/jsx-uses-vars": 0,
"react/no-access-state-in-setstate": 2,
"react/no-adjacent-inline-elements": 0,
"react/no-array-index-key": 0,
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-config-adeira/src/presets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = ({
'no-restricted-globals': OFF,
'no-shadow': OFF,
'no-shadow-restricted-names': ERROR,
'no-undef': ERROR,
'no-undef': OFF, // not needed with Flow and `hermes-eslint` parser (superfluous rule)
'no-undef-init': ERROR,
'no-undefined': OFF,
'no-unused-vars': [
Expand Down
4 changes: 2 additions & 2 deletions src/eslint-config-adeira/src/presets/flowtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = ({
'ft-flow/array-style-simple-type': OFF,
'ft-flow/arrow-parens': OFF,
'ft-flow/boolean-style': [NEXT_VERSION_ERROR, 'boolean'],
'ft-flow/define-flow-type': WARN,
'ft-flow/define-flow-type': OFF, // not needed with `hermes-eslint` parser
'ft-flow/delimiter-dangle': OFF,
'ft-flow/enforce-line-break': OFF,
'ft-flow/enforce-suppression-code': ERROR,
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = ({
'ft-flow/type-id-match': OFF,
'ft-flow/type-import-style': OFF,
'ft-flow/union-intersection-spacing': OFF,
'ft-flow/use-flow-type': WARN,
'ft-flow/use-flow-type': OFF, // not needed with `hermes-eslint` parser
'ft-flow/use-read-only-spread': ERROR,
'ft-flow/valid-syntax': OFF,

Expand Down
6 changes: 3 additions & 3 deletions src/eslint-config-adeira/src/presets/react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

const { ERROR, OFF, WARN, NEXT_VERSION_ERROR } = require('../constants');
const { ERROR, OFF, NEXT_VERSION_ERROR } = require('../constants');
const detectReactVersion = require('../detectReactVersion');

/*::
Expand Down Expand Up @@ -76,8 +76,8 @@ module.exports = ({
'react/jsx-props-no-spreading': OFF,
'react/jsx-sort-default-props': OFF,
'react/jsx-sort-props': OFF,
'react/jsx-uses-react': WARN,
'react/jsx-uses-vars': ERROR,
'react/jsx-uses-react': OFF, // not needed with `hermes-eslint` parser
'react/jsx-uses-vars': OFF, // not needed with `hermes-eslint` parser
'react/no-access-state-in-setstate': ERROR,
'react/no-array-index-key': OFF,
'react/no-arrow-function-lifecycle': ERROR,
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-fixtures-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"dependencies": {
"@adeira/flow-types-eslint": "0.0.0",
"@adeira/js": "^2.1.1",
"@babel/eslint-parser": "^7.18.2",
"@babel/runtime": "^7.18.6",
"eslint": "^8.19.0",
"hermes-eslint": "^0.9.0",
"jest-docblock": "^28.1.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-fixtures-tester/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function testFixtures({
}

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parser: require.resolve('hermes-eslint'),
});

ruleTester.run('no-unused-stylesheet', rule, {
Expand Down
4 changes: 2 additions & 2 deletions src/eslint-plugin-adeira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"devDependencies": {
"@adeira/eslint-fixtures-tester": "0.1.0",
"@adeira/flow-types-eslint": "0.0.0",
"@babel/eslint-parser": "^7.18.2",
"eslint": "^8.19.0"
"eslint": "^8.19.0",
"hermes-eslint": "^0.9.0"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const RuleTester = require('eslint').RuleTester;
const rule = require('../graphql-require-object-description');

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parser: require.resolve('hermes-eslint'),
});

ruleTester.run('graphql-require-object-description', rule, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const RuleTester = require('eslint').RuleTester;
const rule = require('../no-duplicate-import-type-import');

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parser: require.resolve('hermes-eslint'),
});

ruleTester.run('no-duplicate-import', rule, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const RuleTester = require('eslint').RuleTester;
const rule = require('../valid-test-folder');

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parser: require.resolve('hermes-eslint'),
});

ruleTester.run('valid-test-folder', rule, {
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-plugin-sx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@adeira/flow-types-eslint": "0.0.0",
"@adeira/sx": "^0.29.1",
"@babel/code-frame": "^7.18.6",
"@babel/eslint-parser": "^7.18.2",
"eslint": "^8.19.0",
"hermes-eslint": "^0.9.0",
"react": "^18.2.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ testFixtures({
});

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parser: require.resolve('hermes-eslint'),
});

// This test makes sure we are reporting correct lines and columns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ it('returns request body with uploadables', () => {
},
{ bbb: 222 }, // variables
{
foo: new File(['foo'], 'foo.txt'), // eslint-disable-line no-undef
bar: new File(['bar'], 'bar.txt'), // eslint-disable-line no-undef
foo: new File(['foo'], 'foo.txt'),
bar: new File(['bar'], 'bar.txt'),
},
);

Expand All @@ -67,8 +67,8 @@ it('returns request body with uploadables - persistent queries', () => {
},
{}, // variables
{
foo: new File(['foo'], 'foo.txt'), // eslint-disable-line no-undef
bar: new File(['bar'], 'bar.txt'), // eslint-disable-line no-undef
foo: new File(['foo'], 'foo.txt'),
bar: new File(['bar'], 'bar.txt'),
},
);

Expand Down

0 comments on commit 66e29f6

Please sign in to comment.