eslint-plugin-complete
v1.0.2
Published
An ESLint plugin that contains useful rules.
Downloads
980
Maintainers
Readme
eslint-plugin-complete
eslint-plugin-complete
is a collection of miscellaneous ESLint rules that can help make your TypeScript code more safe or more strict.
If you already have ESLint set up in your project, then you can try enabling the complete/recommend
config to get all of the goodness from this plugin in your project at once. Alternatively, if you want more control, feel free to enable the specific rules that you need.
Alternatively, if you want to get off the ground and running with ESLint + TypeScript in a new project, then you should check out the complete-lint
meta-package.
Install / Usage
If you do not want to use the complete-lint
meta-package, then you can install this plugin manually:
npm install --save-dev eslint typescript eslint-plugin-complete
(eslint
andtypescript
are peer-dependencies)- TODO
- Add
"plugin:complete/recommended"
to theextends
section of your.eslintrc.cjs
file. (This will automatically add the plugin and add all of the recommended rules.)- Alternatively, if you want to only enable some specific rules, then add
"complete"
to theplugins
section of your.eslintrc.cjs
file, and then add the specific rules that you want in therules
section.
- Alternatively, if you want to only enable some specific rules, then add
Configs
recommended
- Currently, every rule in this plugin is recommended.
Rules
Each rule has emojis denoting:
- :white_check_mark: - if it belongs to the
recommended
configuration - :wrench: - if some problems reported by the rule are automatically fixable by the
--fix
command line option - :thought_balloon: - if it requires type information
| Name | Description | :white_check_mark: | :wrench: | :thought_balloon: |
| ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------ | -------- | ----------------- |
| complete/complete-sentences-jsdoc
| Requires complete sentences for JSDoc comments | :white_check_mark: | | |
| complete/complete-sentences-line-comments
| Requires complete sentences for multi-line leading line comments | :white_check_mark: | | |
| complete/consistent-enum-values
| Requires consistent enum values | :white_check_mark: | | |
| complete/consistent-named-tuples
| Requires that if one or more tuple elements are named, all of them are named | :white_check_mark: | | |
| complete/eqeqeq-fix
| Requires the use of ===
and !==
(and automatically fixes) | :white_check_mark: | :wrench: | |
| complete/format-jsdoc-comments
| Disallows /**
comments longer than N characters and multi-line comments that can be merged together | :white_check_mark: | :wrench: | |
| complete/format-line-comments
| Disallows //
comments longer than N characters and multi-line comments that can be merged together | :white_check_mark: | :wrench: | |
| complete/jsdoc-code-block-language
| Requires a language specification for every JSDoc code block | :white_check_mark: | | |
| complete/newline-between-switch-case
| Requires newlines between switch cases | :white_check_mark: | :wrench: | |
| complete/no-confusing-set-methods
| Disallows confusing methods for sets | :white_check_mark: | | :thought_balloon: |
| complete/no-empty-jsdoc
| Disallows empty JSDoc comments | :white_check_mark: | :wrench: | |
| complete/no-empty-line-comments
| Disallows empty line comments | :white_check_mark: | :wrench: | |
| complete/no-explicit-array-loops
| Disallows explicit iteration for arrays | :white_check_mark: | :wrench: | :thought_balloon: |
| complete/no-explicit-map-set-loops
| Disallows explicit iteration for maps and sets | :white_check_mark: | :wrench: | :thought_balloon: |
| complete/no-for-in
| Disallows "for x in y" statements | :white_check_mark: | | |
| complete/no-let-any
| Disallows declaring variables with let that do not have a type | :white_check_mark: | | :thought_balloon: |
| complete/no-mutable-return
| Disallows returning mutable arrays, maps, and sets from functions | :white_check_mark: | | :thought_balloon: |
| complete/no-number-enums
| Disallows number enums | :white_check_mark: | | |
| complete/no-object-any
| Disallows declaring objects and arrays that do not have a type | :white_check_mark: | | :thought_balloon: |
| complete/no-object-methods-with-map-set
| Disallows using object methods with maps and sets | :white_check_mark: | | :thought_balloon: |
| complete/no-string-length-0
| Disallows checking for empty strings via the length method in favor of direct comparison to an empty string | :white_check_mark: | | :thought_balloon: |
| complete/no-template-curly-in-string-fix
| Disallows template literal placeholder syntax in regular strings (and automatically fixes) | :white_check_mark: | :wrench: | |
| complete/no-undefined-return-type
| Disallows undefined
return types on functions | :white_check_mark: | | :thought_balloon: |
| complete/no-unnecessary-assignment
| Disallows useless assignments | :white_check_mark: | | :thought_balloon: |
| complete/no-unsafe-plusplus
| Disallow unsafe and confusing uses of the "++" and "--" operators | :white_check_mark: | | :thought_balloon: |
| complete/no-useless-return
| Disallow redundant return statements (with no auto-fixer) | :white_check_mark: | | |
| complete/no-void-return-type
| Disallows void
return types on non-exported functions | :white_check_mark: | :wrench: | |
| complete/prefer-const
| Require const
declarations for variables that are never reassigned after declared (with no auto-fixer) | :white_check_mark: | | |
| complete/prefer-plusplus
| Require "++" or "--" operators instead of assignment operators where applicable | :white_check_mark: | :wrench: | |
| complete/prefer-postfix-plusplus
| Require "i++" instead of "++i" | :white_check_mark: | | :thought_balloon: |
| complete/prefer-readonly-parameter-types
| Require function parameters to be typed as readonly
to prevent accidental mutation of inputs | :white_check_mark: | | :thought_balloon: |
| complete/require-break
| Requires that each case of a switch statement has a break
statement | :white_check_mark: | | |
| complete/require-capital-const-assertions
| Requires a capital letter for named objects and arrays that have a const assertion | :white_check_mark: | :wrench: | |
| complete/require-capital-read-only
| Requires maps/sets/arrays with a capital letter to be read-only | :white_check_mark: | | :thought_balloon: |
| complete/require-unannotated-const-assertions
| Disallows explicit type annotations for variables that have a const assertion | :white_check_mark: | | |
| complete/require-variadic-function-argument
| Requires that variadic functions must be supplied with at least one argument | :white_check_mark: | | :thought_balloon: |
| complete/strict-array-methods
| Requires boolean return types on array method functions | :white_check_mark: | | :thought_balloon: |
| complete/strict-enums
| Disallows the usage of unsafe enum patterns | :white_check_mark: | | :thought_balloon: |
| complete/strict-undefined-functions
| Disallows empty return statements in functions annotated as returning undefined | :white_check_mark: | | :thought_balloon: |
| complete/strict-void-functions
| Disallows non-empty return statements in functions annotated as returning void | :white_check_mark: | | |
Automatic Fixing
You probably already use Prettier, which is helpful to automatically format files. You probably even have your IDE set up to run Prettier every time your save a file. This kind of thing saves you a tremendous amount of time - you can type out a bunch of code completely unformatted, and then press Ctrl + s
at the end to automatically fix everything. (Alternatively, you could press Ctrl + shift + f
to format the file without saving it, but it's simpler to just use one hotkey for everything.)
In a similar way to Prettier, this ESLint plugin contains several rules that are designed to automatically apply whenever you save the file (like the format-jsdoc-comments
rule). These rules are "fixers", which are applied when ESLint is executed with the "--fix" flag. So, in the same way that you configure Prettier to run on save, you should also configure eslint --fix
to run on save.
For example, if you use VSCode, and you have the Prettier and the ESLint extensions installed, you can add the following to your repository's .vscode/settings.json
file:
{
// Automatically run the formatter when certain files are saved.
"[javascript][typescript][javascriptreact][typescriptreact]": {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
}
Comment Formatting
For a discussion around comments and the motivations for some of the comment rules in the plugin, see this page.
Contributing
Thanks for helping out with this open-source project!
If you are adding a new rule, start by using the create-rule
script to automate a few things:
npm run create-rule foo "This is a description of the foo rule."
git status # Show what the script did.
Additionally, You can contact me on Discord if you are doing a PR and have questions.