eslint-plugin-misc
v3.3.1
Published
ESLint plugin
Downloads
1,464
Readme
ESLint plugin
Table of contents
Overview
A collection of ESLint rules for JavaScript and TypeScript files.
Installation
npm install --save-dev eslint-plugin-misc
// .eslintrc.js
module.exports = {
extends: "plugin:misc/all",
parser: "@typescript-eslint/parser",
plugins: ["misc"]
};
Configs
- plugin:misc/all — All rules.
- plugin:misc/recommended — Recommended rules.
- plugin:misc/core — Core rules.
- plugin:misc/typescript — Rules for typescript files.
Rules
- class-match-filename — Requires class name to match filename.
- comment-spacing — Requires consistent empty lines around comments.
- consistent-empty-lines — Requires consistent empty lines.
- consistent-enum-members — Requires consistent key-value pairs inside enums (key should match value).
- consistent-filename — Enforces consistent file name format.
- consistent-import — Requires consistent import.
- consistent-optional-props — Ensures consistent optional property style.
- consistent-source-extension — Requires consistent import/export source extension.
- consistent-symbol-description — Requires consistent symbol description.
- disallow-import — Disallows import given sources.
- export-matching-filename-only — Requires that export matching filename is the only export.
- match-filename — Requires that AST element matches filename.
- max-identifier-blocks — Restricts identifier complexity.
- no-at-sign-import — Disallows "@" import.
- no-at-sign-internal-import — Disallows "@/**" import.
- no-chain-coalescence-mixture — Disallows mixing of chain and coalescence operators.
- no-expression-empty-lines — Disallows empty lines inside expressions.
- no-index-import — Disallows "." import.
- no-internal-modules — Disallows importing of internal modules.
- no-language-mixing — Disallows language mixing.
- no-negated-conditions — Disallows negated conditions.
- no-nodejs-modules — Disallows importing NodeJS modules.
- no-param-reassign — This rule wraps "no-param-reassign" core rule, but allows to edit params at the top of function body.
- no-relative-parent-import — Disallows relative parent import.
- no-restricted-syntax — Disallows AST syntax (an extended version of ESLint core rule).
- no-self-import — Disallows self-import.
- no-shadow — This rule wraps "@typescript-eslint/no-shadow" rule, but skips checking enum.
- no-sibling-import — Restricts importing siblings.
- no-underscore-export — Disallows underscore export.
- no-unnecessary-as-const — Disallows unnecessary "as const".
- no-unnecessary-break — Disallows unnecessary "break".
- no-unnecessary-initialization — Disallows unnecessary initialization.
- no-unnecessary-template-literal — Disallows unnecessary template literals.
- object-format — Requires multiline or single-line object format.
- only-export-name — Requires that only export matches filename.
- prefer-arrow-function-property — Requires use of arrow functions.
- prefer-const-require — Requires "require()" to be assigned to variable.
- prefer-only-export — Requires only export if given AST element is found.
- require-jsdoc — Requires JSDoc documentation.
- require-syntax — Requires AST syntax.
- restrict-identifier-characters — Requires that identifier consists only of english characters and dollar sign.
- sort-array — Sorts arrays.
- sort-call-signature — Requires call signature to be first child.
- sort-class-members — Sorts class members by type and alphabetically inside each type group.
- sort-construct-signature — Requires construct signature to be first child.
- sort-export-specifiers — Sorts export specifiers.
- sort-keys — Sorts object keys.
- sort-top-comments — Sorts top comments.
- switch-case-spacing — Ensures consistent empty lines between switch case statements.
- template-literal-format — Requires consistent padding in template literals.
- wrap — Wraps and modifies third-party rule.
- typescript/array-callback-return-type — Requires boolean return type in array callbacks.
- typescript/class-methods-use-this — This rule wraps "class-methods-use-this" core rule, but skips methods with "this: void" argument.
- typescript/consistent-array-type-name — Requires consistent array type name.
- typescript/define-function-in-one-statement — Requires that function is defined in one statement.
- typescript/exhaustive-switch — Checks exhaustiveness of switch statement.
- typescript/no-boolean-literal-type — Disallows boolean literal type.
- typescript/no-complex-declarator-type — Requires either 'as const' or type definition complex declarators.
- typescript/no-complex-return-type — Disallow complex function return types.
- typescript/no-empty-interfaces — Disallow empty interfaces.
- typescript/no-inferrable-types — Reports inferrable types.
- typescript/no-multi-type-tuples — Disallows multi-type tuples.
- typescript/no-never — Disallow "never" type.
- typescript/no-restricted-syntax — Disallows AST syntax with additional type check.
- typescript/no-unsafe-object-assign — Disallows unsafe "Object.assign".
- typescript/no-unsafe-object-assignment — Reports unsafe object assignments.
- typescript/prefer-array-type-alias — Prefer alias for array type.
- typescript/prefer-class-method — Requires use of class methods instead of function properties.
- typescript/prefer-enum — Requires using enums instead of string literals.
- typescript/prefer-readonly-array — Disallows writable arrays.
- typescript/prefer-readonly-map — Disallows writable maps.
- typescript/prefer-readonly-property — Disallows writable properties.
- typescript/prefer-readonly-set — Disallows writable sets.
- typescript/require-prop-type-annotation — Requires type annotation for class properties.
- typescript/require-this-void — Requires "this: void" for static methods.
Synonyms
You can use the same rule several times by adding synonym:
// .eslintrc.synonyms.cjs
module.exports = ["misc/wrap/class-methods-use-this", "misc/wrap/no-shadow"];
// .eslintrc.js
module.exports = {
rules: {
// Same as ESLint core rule, but suppresses warnings for methods that have "this" parameter.
"misc/wrap/class-methods-use-this": [
"error",
{
plugin: "eslint",
rule: "class-methods-use-this",
skip: "FunctionExpression[params.0.name=this]"
}
],
// Same as typescript-eslint rule, but suppresses warnings for enums.
"misc/wrap/no-shadow": [
"error",
{
plugin: "@typescript-eslint/eslint-plugin",
rule: "no-shadow",
skip: "TSEnumDeclaration *"
}
]
}
};
Custom checks
Many custom checks can be created without writing full-fledged ESLint plugin. Use the rules below to create custom checks or adapt existing third-party rules:
- no-restricted-syntax — Disallows AST syntax (an extended version of ESLint core rule).
- require-syntax — Requires AST syntax.
- wrap — Wraps and modifies third-party rule.
- typescript/no-restricted-syntax — Disallows AST syntax with additional type check.
If you want to apply one rule several times (e.g. restrict several syntaxes), use rule synonyms.
Planned rules
- boolean-in-boolean-context — Require strict boolean type in boolean contexts like
x && y
or!x
. - consistent-import-as — Require that y in
import { x as y }
statement is from allowed list. - consistent-test-file-name — Require that test file name matches some source file name.
- no-re-export-mixing — Require that file contains either only re-export or only export of new items.
- escape-doc-comment-entities — Require that "<" and ">" symbols inside doc comments are properly escaped.
- no-array-mutation — Forbid array mutation.
- no-duplicate-import — Forbid combining
import { x } from "source"
andimport { x as y } from "source"
in the same file. - protected-rules — Do not allow to disable selected ESLint rules.
- sort-eslint-comments — Sort rules in eslint-disable comments.
- sort-switch-cases — Sort switch cases.
- spell-check — Spell check with international language support based on hunspell spell checker.