This is a shared configuration for all Tree repositories. Contains overrides and enhancements on top of the base configuration located at https://github.com/fs-webdev/eslint-config-frontier.
This central configuration is a potential breaking point for all of our code if we suddenly break our rules, so we have tests in place that verify that our configuration remains consistent between upgrades (primarily that we know what changed), and that the extended cases that we care about are still caught. We do this by utilizing ava's snapshot ability against exported (and slightly modified) linting output and linting configuration. These files are not committed, as they are re-created on each test run, but the resulting snapshot and summary markdown file are part of version control, to make it easier to see changes.
Process:
- Run
npm test
(to determine if any significant rules have changed since the last release)
- The tests will likely fail. Verify newly-consumed rules against the current snapshot file.
- After verifying, run
npm run test:update
. - Make dependency/configuration updates.
- Run
npm test
(to determine new changes in linting results or configuration).
- The tests should likely fail. Verify your expectations against the current snapshot file.
- After you have your results how you want them, run
npm run test:update
.
- The tests should now pass.
Why extra rules? Because we believe in linting, and we have become converted to the additional rules enforced by the following plugins:
- eslint-plugin-bestpractices
- eslint-plugin-deprecate
- eslint-plugin-html
- eslint-plugin-import (implemented by Frontier)
- eslint-plugin-jsdoc
- eslint-plugin-json (adopted by Frontier)
- eslint-plugin-promise
- eslint-plugin-sonarjs
POTENTIALLY WORTH CONSIDERING IN THE FUTURE (MAY NOT WORK BECAUSE OF NEEDING SOMETHING EXTRA?):
- 'eslint-plugin-i18next' // SEEMS LIKE TOO MANY FALSE POSITIVES
- 'eslint-plugin-json-format' // DOESN'T SEEM TO WORK
- 'eslint-plugin-package-json' // undefined TypeErrors while parsing package.json
- 'eslint-plugin-sort-keys-fix' // RUINS INDENTATION, DOES NOT BRING JSDOCS ALONG
-
Add this repository as a package devDependency:
"eslint-config-tree": "github:fs-webdev/eslint-config-tree#semver:^6",
-
Add an
eslintrc.js
file, with the following:
module.exports = {
extends: [
'eslint-config-tree'
]
}
- Enjoy.
Add an eslintrc.js
file to that directory with the necessary overrides, like so:
module.exports = {
rules: {
'bestpractices/no-eslint-disable': 'off|warn|error',
}
}
Add an overrides
section to your eslintrc.js
file to target those files with the necessary overrides, like so:
overrides: [
{
files: ['*.stories.js', '*.test.js'],
rules: {
// We do not need to enforce selector rules in test/demo files
'test-selectors/button': 'off',
'test-selectors/onChange': 'off',
},
},
],
Utilize a file linting config modifier like so:
/* eslint no-console: "off" -- node scripts use the console */
Note that --
comments are permitted and a very good idea to include.
If you are seeing these warnings when linting locally, you may have eslint
installed globally, but not the additional dependency. We do not recommend running eslint
globally for this reason (see: eslint/eslint#6732). All Tree repositories should include all dependencies required to be able to run eslint
locally in their respective directories.
If you have recently updated dependencies and see this error locally, then there is a possibility that your editor's linting integration is out-of-sync that can be resolved by restarting your editor.
The jsdoc
warnings are only triggered for functions that have an jsdoc extended comment block (/** */
) directly above the function declaration. Omit this, add an extra space, or just use a short comment (//
) or a standard extended comment (/* */
) to keep from applying jsdoc
rules to functions not requiring fastidious documentation. Or follow all of the rules.
Maintenance Notes
Occasionally, there may be an update which breaks a rule in particular or linting in general. To this end, when running npm test
, we output the current linting results to a text file, clean it up a little, and employ ava to run a snapshot comparison unit test to determine if our linting output has changed from the previous run.
If there has been a change (say you added a new rule, or there is a new valid violation triggered), you can update the snapshot via npm run test:update
.
- Why no lockfile? Because we (currently) trust our dependencies, and do not want to constantly have to be verifying and manually releasing new versions of this convenience configuration. We may decide to be more precise in the future.
- As noted in the
Testing/Updating
section, the only validation we do is to run linting against a file with a set of known failures. So we make sure to runnpm test
via a pre-push hook, and releases are automatically performed by a GitHub webhook. - Because this is a public repository, there are complications in adding references to private services and communications channels, so there is no Travis CI build.
- Coverage reporting ends up reporting on
lint-output.js
, instead ofindex.js
, which is unhelpful, and so is also not used, for now.
Version 6 - ESLint 8
- Update all linting subdependencies. Remove redundant plugins (eslint-plugin-json adopted by Frontier).
- Remove Code Climate/Polymer-related configurations and documentation.
- Add new final configuration test.
- Inherit more configuration from frontier (finally).
Version 5
- Update all linting subdependencies.
- Add new rules.
- Set more reasonable defaults for some rules.
- Add best practices and examples for managing linting in varying projects.
Version 4
eslint-plugin-no-only-tests
&eslint-plugin-no-skip-tests
are redundant to to newly-implementedjest/no-focused-tests
&jest/no-disabled-tests
and have been removed.
Version 3 - ESLint 7
- ESLint and dependencies updated to version 7.
Version 2 - ESLint 6
- ESLint and dependencies based on version 6.
Version 1 - ESLint 5
- ESLint and dependencies based on version 5.
- Add eslint-plugin-bestpractices, eslint-plugin-deprecate, eslint-plugin-html, eslint-plugin-jsdoc, eslint-plugin-json, eslint-plugin-promise, eslint-plugin-sonarjs, eslint-config-standard