Skip to content

Commit

Permalink
Get working for eslint 8 with flowtype plugin (#33)
Browse files Browse the repository at this point in the history
## Summary:
So, it was failing to resolve `eslint/use-at-your-own-risk` from inside a plugin.
I suspect this was down to module resoluton issues due to the way we programmatically require `eslint`.
So, rather than do that, I wrote it to invoke the CLI instead and let GitHub scrape the annotations (which it supports).

This feels more robust to future change by keeping the action's node module resolution independent of the code being checked.

I don't know why the lint step is doing what it's doing. I ran lint locally and all is fine - I suspect it may be suffering from the same issue that I'm fixing with this PR.

Issue: FEI-4138

## Test plan:
I added this to my webapp PR and checked that it now works (waiting on final confirmation, but it's doing far more than it was before these changes)
See https://github.com/Khan/webapp/runs/4292013711?check_suite_focus=true

Author: somewhatabstract

Reviewers: somewhatabstract, jeresig

Required Reviewers:

Approved By: jeresig

Checks: ❌ lint_and_unit, ✅ autofix

Pull Request URL: #33
  • Loading branch information
somewhatabstract authored Nov 23, 2021
1 parent 1da5c69 commit d2cca53
Show file tree
Hide file tree
Showing 10 changed files with 134,398 additions and 116,016 deletions.
80 changes: 57 additions & 23 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"node": true,
"jest": true
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module"
},
"plugins": ["flowtype"],
"parser": "@babel/eslint-parser",
"plugins": [
"prettier",
"flowtype",
"@babel"
],
"rules": {
"prettier/prettier": "error",
// The default rule wants to enforce // @flow, but we frequently have it
// as part of the file's docstring.
"flowtype/require-valid-file-annotation": [0, "always"],
"flowtype/require-valid-file-annotation": [
0,
"always"
],
// ---------------------------------------
// ES6 rules.
"constructor-super": 2,
Expand All @@ -35,14 +40,25 @@
2,
{
"properties": "never",
"allow": ["^UNSAFE_"]
"allow": [
"^UNSAFE_"
]
}
],
"curly": 2,
"eqeqeq": [2, "allow-null"],
"eqeqeq": [
2,
"allow-null"
],
"guard-for-in": 2,
"linebreak-style": [2, "unix"],
"max-lines": [2, 1000],
"linebreak-style": [
2,
"unix"
],
"max-lines": [
2,
1000
],
"no-alert": 2,
"no-array-constructor": 2,
"no-debugger": 2,
Expand All @@ -59,12 +75,24 @@
// NOTE: If you change the options here, be sure to update eslintrc.flow also
"no-unused-expressions": [
2,
{"allowShortCircuit": true, "allowTernary": true}
{
"allowShortCircuit": true,
"allowTernary": true
}
],
"no-unused-vars": [
2,
{
"args": "none",
"varsIgnorePattern": "^_*$"
}
],
"no-unused-vars": [2, {"args": "none", "varsIgnorePattern": "^_*$"}],
"no-useless-call": 2,
"no-with": 2,
"one-var": [2, "never"],
"one-var": [
2,
"never"
],
// TODO(scottgrant): Add additional a11y rules as we support them.
// ---------------------------------------
// Stuff that's disabled for now, but maybe shouldn't be.
Expand All @@ -76,16 +104,20 @@
// use jsdoc anywhere it seems silly to require it yet.
"valid-jsdoc": 0,
"require-jsdoc": 0,
"flowtype/boolean-style": [2, "boolean"],
"flowtype/boolean-style": [
2,
"boolean"
],
"flowtype/define-flow-type": 1, // suppress no-undef on flow types
"flowtype/no-dupe-keys": 2,

// Use Flow's version of no-unused-expressions
"flowtype/no-unused-expressions": [
2,
{"allowShortCircuit": true, "allowTernary": true}
{
"allowShortCircuit": true,
"allowTernary": true
}
],

"flowtype/no-weak-types": 0, // allow 'any' for now
// flow may still require parameter types in certain situations
"flowtype/require-parameter-type": 0,
Expand All @@ -94,11 +126,13 @@
"flowtype/type-id-match": 0,
"flowtype/use-flow-type": 1 // suppress no-unused-vars on flow types
},
"extends": ["prettier/flowtype"],
"extends": [
"prettier"
],
"globals": {
"DEBUG": false,
"Promise": false,
"Set": false,
"__DEV__": [false /* writable */, true /* readable */]
"DEBUG": "readonly",
"Promise": "readonly",
"Set": "readonly",
"__DEV__": "readonly"
}
}
}
2 changes: 1 addition & 1 deletion .github/workflow-templates/pr-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Run prettier
setup: yarn
run: node ./node_modules/actions-utils/list-changed-files.js | grep '.*\.js$' | xargs npm run -s format-files
run: node ./node_modules/actions-utils/list-changed-files.js main | grep '.*\.js$' | xargs npm run -s format-files

- name: Rebuild our "dist" file
setup: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-autofix.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.cache
.idea
coverage
yarn-error.log
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parser": "babel-flow",
"tabWidth": 4,
"printWidth": 100,
"trailingComma": "all",
Expand Down
3 changes: 1 addition & 2 deletions __test__/empty.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow

describe('a test that does nothing', () => {
it('should work', async () => {
});
it('should work', async () => {});
});
Loading

0 comments on commit d2cca53

Please sign in to comment.