-
Notifications
You must be signed in to change notification settings - Fork 162
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
Update eslint rules #1665
Update eslint rules #1665
Commits on Apr 25, 2023
-
Configuration menu - View commit details
-
Copy full SHA for b5d2ec0 - Browse repository at this point
Copy the full SHA b5d2ec0View commit details -
Clarify existing scope of ESLint
Currently, the ESLint configuration file is top-level but only files under src/ are linted according to the npm script. This is a bit disjoint. Two options: 1. Move all usage of ESLint to src/. 2. Work towards applying ESLint to all files in this project. I'm going with (2) since there are some unlinted files that could benefit from linting. The first step, done by this commit, is to update the npm script and specify the unlinted files explicitly in .eslintignore (also removing unused ESLint exceptions from these files). Future commits will continue in this direction.
Configuration menu - View commit details
-
Copy full SHA for 7878ac4 - Browse repository at this point
Copy the full SHA 7878ac4View commit details -
This was added in 55f4842 for context of where the initial rules came from. The rules have since deviated from the linked configuration file.
Configuration menu - View commit details
-
Copy full SHA for d5217e7 - Browse repository at this point
Copy the full SHA d5217e7View commit details -
eslint: Add extension to config file
The extension-less configuration file name was deprecated more than 5 years ago¹, and the deprecation message is no longer present in the official documentation. Even though the extension-less file still works fine, the rename serves to keep up-to-date with documented formats and make it clear to some text editors that YAML is the format used in this file. ¹ https://dev.to/ohbarye/eslintrc-without-file-extension-is-deprecated-3ngg
Configuration menu - View commit details
-
Copy full SHA for cbb40e5 - Browse repository at this point
Copy the full SHA cbb40e5View commit details
Commits on May 4, 2023
-
eslint: Replace Airbnb base config
The Airbnb base config was presumably adopted early on with good intents, but over time the ESLint config file has become littered with overrides to disable many rules enabled by this base config. To me, it seems the main reason is that the Airbnb base config includes both code-quality rules and code-style rules, while we have chosen to ignore most code-style rules. The "recommended" base configs mostly¹ set code-quality rules. Using these as a replacement for the Airbnb base config means much of the rule overrides are no longer necessary. Note: some new overrides were added to avoid code changes. These will be addressed in subsequent commits. ¹ eslint:recommended enables `no-mixed-spaces-and-tabs`, which is probably fine. https://eslint.org/docs/latest/rules
Configuration menu - View commit details
-
Copy full SHA for b3cedb7 - Browse repository at this point
Copy the full SHA b3cedb7View commit details -
Run ESLint on cli/, scripts/, test/
Files in these directories should be held to the same standards as files in src/.
Configuration menu - View commit details
-
Copy full SHA for 7c42bc8 - Browse repository at this point
Copy the full SHA 7c42bc8View commit details -
I can no longer find ESLint 7 rules documentation on the official website¹. The upgrade doesn't introduce any breaking changes for current usage, and now (while going through rules) would be a good time to upgrade. This will make it easier to reference rule doc pages in subsequent commits. ¹ https://eslint.org/docs
Configuration menu - View commit details
-
Copy full SHA for 103e527 - Browse repository at this point
Copy the full SHA 103e527View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3964bf9 - Browse repository at this point
Copy the full SHA 3964bf9View commit details -
eslint: Address no-case-declarations violations
Lexical declarations (let/const/etc.) are discouraged in case blocks since they are accessible to the entire switch block (unless scoped by curly brackets). None of the impacted declarations are currently used outside of their case block scopes, so all that's needed here is to add curly brackets. Rule doc page: https://eslint.org/docs/latest/rules/no-case-declarations
Configuration menu - View commit details
-
Copy full SHA for 1e22f41 - Browse repository at this point
Copy the full SHA 1e22f41View commit details -
eslint: Address no-compare-neg-zero violations
This is scoped to usages of the same pattern in one file. Two options: 1. Ignore the lines explicitly rather than across the whole project. 2. Apply the alternative from the rule doc page. Going with (2) since it seems reasonable. Also added a link to the actual bug since it took some time to dig that up. Rule doc page: https://eslint.org/docs/latest/rules/no-compare-neg-zero
Configuration menu - View commit details
-
Copy full SHA for 94bea96 - Browse repository at this point
Copy the full SHA 94bea96View commit details -
eslint: Address no-cond-assign violations
There is just one, which can be wrapped in parentheses to make it valid. Rule doc page: https://eslint.org/docs/latest/rules/no-cond-assign
Configuration menu - View commit details
-
Copy full SHA for 0b84281 - Browse repository at this point
Copy the full SHA 0b84281View commit details -
eslint: Address no-prototype-builtins violations
The recommendation to use `Object.prototype.hasOwnProperty.call()` is already used elsewhere in this codebase, so I assume these deviations were due to unintentional oversight. Rule doc page: https://eslint.org/docs/latest/rules/no-prototype-builtins
Configuration menu - View commit details
-
Copy full SHA for b0809d3 - Browse repository at this point
Copy the full SHA b0809d3View commit details -
eslint: Partially address no-unused-vars violations
Since the existing unused variables have somewhat meaningful names, add underscores to these names and configure the rule to allow underscore-prefixed names to be unused. This commit does not address unused imports and functions - those are temporarily disabled by line and will be addressed in following commits.
Configuration menu - View commit details
-
Copy full SHA for f8bca60 - Browse repository at this point
Copy the full SHA f8bca60View commit details -
Remove unused node-fetch import
node-fetch is no longer necessary as a direct dependency. Move it to devDependencies since it is still used in a test.
Configuration menu - View commit details
-
Copy full SHA for 98ae4d9 - Browse repository at this point
Copy the full SHA 98ae4d9View commit details -
Keep the direct dependency since it is still used in src/util/parseMarkdown.js.
Configuration menu - View commit details
-
Copy full SHA for 57769cf - Browse repository at this point
Copy the full SHA 57769cfView commit details -
Remove unused function isValidJSONCallback
The only usage was removed in a7bfd62.
Configuration menu - View commit details
-
Copy full SHA for c9cea8d - Browse repository at this point
Copy the full SHA c9cea8dView commit details -
eslint: Address react/no-deprecated violations
There are better ways to address these (componentWillMount¹, componentWillReceiveProps²). I opted for the rename to avoid complex code changes. ¹ https://legacy.reactjs.org/docs/react-component.html#unsafe_componentwillmount ² https://legacy.reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops
Configuration menu - View commit details
-
Copy full SHA for 53dc6aa - Browse repository at this point
Copy the full SHA 53dc6aaView commit details -
eslint: Address react/no-direct-mutation-state violations
There is only one, so disable it for the specific line. A proper fix will come in the following commit.
Configuration menu - View commit details
-
Copy full SHA for 7c7cdce - Browse repository at this point
Copy the full SHA 7c7cdceView commit details -
Configuration menu - View commit details
-
Copy full SHA for f80a98e - Browse repository at this point
Copy the full SHA f80a98eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9d5db44 - Browse repository at this point
Copy the full SHA 9d5db44View commit details -
eslint-plugin-react: Detect React version
Previously when missing, it defaulted to "latest" and showed a warning.
Configuration menu - View commit details
-
Copy full SHA for 902895a - Browse repository at this point
Copy the full SHA 902895aView commit details -
eslint: Section by "code quality" and "code style" rules
No code style rules yet but they will be added in subsequent commits.
Configuration menu - View commit details
-
Copy full SHA for 74f76ad - Browse repository at this point
Copy the full SHA 74f76adView commit details -
Use a src-specific ESLint config file
This takes advantage of configuration cascading¹ so rules that only apply within src aren't applied elsewhere. ¹ https://eslint.org/docs/latest/use/configure/configuration-files#cascading-and-hierarchy
Configuration menu - View commit details
-
Copy full SHA for a9aab1d - Browse repository at this point
Copy the full SHA a9aab1dView commit details -
James went through all the rules that we had custom-enabled prior to b3cedb7. These are the ones that were flagged to be re-added. Some are commented out since there are existing violations. Subsequent commits will un-comment the rules and address violations. Co-authored-by: James Hadfield <hadfield.james@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 71c0709 - Browse repository at this point
Copy the full SHA 71c0709View commit details -
eslint: Address no-use-before-define violations
There is only one, and it is because a function expression is used before it is defined. Changing to a function declaration solves this because those are hoisted to the top-level (function expressions are not). Rule doc page: https://eslint.org/docs/latest/rules/no-use-before-define
Configuration menu - View commit details
-
Copy full SHA for 9fc42f0 - Browse repository at this point
Copy the full SHA 9fc42f0View commit details -
eslint: Address prefer-const violations
As the rule doc page says, if a variable is never reassigned, using the const declaration is better. Rule doc page: https://eslint.org/docs/latest/rules/prefer-const
Configuration menu - View commit details
-
Copy full SHA for 93ee800 - Browse repository at this point
Copy the full SHA 93ee800View commit details -
eslint: Address no-unneeded-ternary violations
This was already disabled from 910e567 and it looks like there's enough context to keep it as-is. Rule doc page: https://eslint.org/docs/latest/rules/no-unneeded-ternary
Configuration menu - View commit details
-
Copy full SHA for eb0c592 - Browse repository at this point
Copy the full SHA eb0c592View commit details -
eslint: Address no-console violations
These seem fine to have, so disable the rule per-line. Rule doc page: https://eslint.org/docs/latest/rules/no-console
Configuration menu - View commit details
-
Copy full SHA for cf2b541 - Browse repository at this point
Copy the full SHA cf2b541View commit details -
Remove unused triggerOutboundEvent
The last reference was removed in 5d63682. This doesn't show up as "unused" during linting since it's possible that downstream code could import this function, but I don't think we have to worry about that for this specific function.
Configuration menu - View commit details
-
Copy full SHA for 5c9c8ca - Browse repository at this point
Copy the full SHA 5c9c8caView commit details -
eslint: Enable react/no-array-index-key
This is enabled in the Airbnb base config¹ that we previously used. It's still useful to have around. It can be disabled for the violation in title.js since using indexes as keys is only discouraged if the order of items may change² (not applicable here). ¹ https://github.com/airbnb/javascript/blob/7982931ba745c0f57ba6934fc7e6cc43901dac76/packages/eslint-config-airbnb/rules/react.js#L388 ² https://legacy.reactjs.org/docs/lists-and-keys.html#keys
Configuration menu - View commit details
-
Copy full SHA for 09b5f3f - Browse repository at this point
Copy the full SHA 09b5f3fView commit details