eslint-rules/README.md
This document outlines the rules we have added to the GitHub Desktop project and how to interact with them.
This project uses rules from a number of sources, but sometimes we need specific rules that aren't available elsewhere. These are added to the eslint-rules/ directory and are configured in the .eslintrc.yml file at the root of the project.
If you wish to add a new rule specific to the project, ensure that there isn't an existing rule available from one of the existing plugins used in the project:
@typescript-eslint/eslint-plugineslint-plugin-babeleslint-plugin-jsdoceslint-plugin-jsoneslint-plugin-prettiereslint-plugin-reactThis project supports two different kinds of ESLint plugins, based on what you are interested in linting:
@typescript-eslint parser
react-proper-lifecycle-methods ruleno-unbound-dispatcher-props ruleHow to write a plugin is out of scope for this documentation, but I've added some resources at the end of this page to help you get started.
The custom ESLint rules are annotated with TypeScript types wherever available, and can be checked through yarn:
$ yarn check:eslint
The eslint-rules/tsconfig.json is setup to guide tsc to understand the environment for running the ESlint rules, and each rule is annotated
with @type hints wherever possible to appease the typechecker.
Tests are added alongside each rule in the eslint-rules/tests/ section, and can be run from the project root through yarn:
$ yarn test:eslint
Each test suite is designed to exercise the relevant rule against code snippets that illustrate both valid and invalid code, and indicate which messages should be reported in case of failure.
If you wish to debug the rules using VSCode, add this action to the configurations array of the .vscode/launch.json settings:
{
"command": "yarn test:eslint",
"name": "Test ESLint scripts",
"request": "launch",
"type": "node-terminal"
}
Running this command will attach the debugger, and allow you to step through the rule with the available test cases.
typescript-estree package - this is part of @typescript-eslint and allows for interop between Typescript code and the estree reference spec that ESLint uses for it's plugins.