Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-etc

cartant286.6kMIT2.0.3

More general-purpose ESLint rules

lint, rules, eslint

readme

eslint-plugin-etc

GitHub License NPM version Downloads Build status dependency status devDependency Status peerDependency Status

This package contains a bunch of general-purpose, TypeScript-related ESLint rules. Essentially, it's a re-implementation of the rules that are in the tslint-etc package.

Some of the rules are rather opinionated and are not included in the recommended configuration. Developers can decide for themselves whether they want to enable opinionated rules.

Install

Install the ESLint TypeScript parser using npm:

npm install @typescript-eslint/parser --save-dev

Install the package using npm:

npm install eslint-plugin-etc --save-dev

Configure the parser and the parserOptions for ESLint. Here, I use a .eslintrc.js file for the configuration:

const { join } = require("path");
module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2019,
    project: join(__dirname, "./tsconfig.json"),
    sourceType: "module"
  },
  plugins: ["etc"],
  extends: [],
  rules: {
    "etc/no-t": "error"
  }
};

Or, using the recommended configuration:

const { join } = require("path");
module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2019,
    project: join(__dirname, "./tsconfig.json"),
    sourceType: "module"
  },
  extends: ["plugin:etc/recommended"],
};

Rules

The package includes the following rules.

Rules marked with ✅ are recommended and rules marked with 🔧 have fixers.

| Rule | Description | | | | --- | --- | --- | --- | | no-assign-mutated-array | Forbids the assignment of returned, mutated arrays. | ✅ | | | no-commented-out-code | Forbids commented-out code. | | | | no-const-enum | Forbids the use of const enum. Constant enums are not compatible with isolated modules. | | | | no-deprecated | Forbids the use of deprecated APIs. | ✅ | | | no-enum | Forbids the use of enum. | | | | no-implicit-any-catch | Like the no-implicit-any-catch rule in @typescript-eslint/eslint-plugin, but for Promise rejections instead of catch clauses. | ✅ | 🔧 | | no-internal | Forbids the use of internal APIs. | ✅ | | | no-misused-generics | Forbids type parameters without inference sites and type parameters that don't add type safety to declarations. This is an ESLint port of Wotan's no-misused-generics rule. See also "The Golden Rule of Generics". | | | | no-t | Forbids single-character type parameters. | | | | prefer-interface | Forbids type aliases where interfaces can be used. | | 🔧 | | prefer-less-than | Forbids greater-than comparisons. (Yes, this is the rule for Ben Lesh comparisons.) | | 🔧 | | throw-error | Forbids throwing - or rejecting with - non-Error values. | | | | underscore-internal | Forbids internal APIs that are not prefixed with underscores. | | |

changelog

2.0.3 (2023-05-10)

Fixes

  • Widen the TypeScript peer dependency. (0b4f07d)

2.0.2 (2022-01-22)

Fixes

  • Don't flag multi-line comments with a single word on each line as code. (ed13864)

2.0.1 (2021-11-08)

Fixes

  • Don't effect failures in the throw-error rule when unknown is thrown. See this issue. (88494f2)

2.0.0 (2021-10-17)

Breaking Changes

  • Support eslint v8 and @typescript-eslint v5. (c827e02)

1.5.4 (2021-07-02)

Fixes

  • Deem binary expressions, identifiers and literals to be non-code in the no-commented-out-code rule. (3317531)

1.5.3 (2021-06-30)

Fixes

  • Fix false positives for trivial comments in interfaces with the no-commented-out-code rule. (c948008)

1.5.2 (2021-06-16)

Changes

  • Replace the use of RegExp to identify comments that can be parsed that aren't really commented-out code. (03517cc)

1.5.1 (2021-06-16)

Fixes

  • Deem labeled statements to be non-code in the no-commented-out-code rule. (e64c8e2)

1.5.0 (2021-05-27)

Features

  • Add the prefer-less-than rule. (17fafab)

1.4.1 (2021-05-27)

Fixes

  • Support TypeScript 4.3 in the no-deprecated and no-internal rules. (43fe310)

1.4.0 (2021-04-15)

Features

  • Add underscore-internal rule. (540574e)

1.3.8 (2021-03-30)

Fixes

  • Support // #endregion comments in no-commented-out-code. (6cb6d67)

1.3.7 (2021-03-22)

Fixes

  • Set minimum eslint-etc version. (fadbbf4)

1.3.6 (2021-03-20)

Fixes

  • Support multiple @deprecated and @internal tags in the no-deprecated and no-internal rules. (20eb236)
  • Enable TypeScript's strict option and fix related problems. (826953c)

1.3.5 (2021-03-14)

Fixes

  • New lines and excess whitespace are now striped from deprecations reported by the no-deprecated rule. (16d19d0)

1.3.4 (2021-03-11)

Fixes

  • Match non-Latin characters in the no-commented-out-code rule to avoid more false positives. (9a7411a)

1.3.3 (2021-02-18)

Changes

  • Tweaked the no-commented-out-code rule to find more comments. (15648f5)

1.3.2 (2021-02-11)

Fixes

  • Ignore whitespace-only comments in the no-commented-out-code rule. (4cfccfa)

1.3.1 (2021-02-11)

Fixes

  • Ignore some basic, unintentionally-parsable comments in the no-commented-out-code rule. (b1263e7)

1.3.0 (2021-02-10)

Features

  • Add a no-commented-out-code rule. (4a7cbc5)

1.2.0 (2021-02-06)

Features

  • The prefer-interface rule now has an allowIntersection option that - when set to false - will replace intersection type aliases with interface extensions. See the docs for more information. (12fab8d)

1.1.10 (2021-02-05)

Fixes

  • Support Array constructors in no-assign-mutated-array. (a5837e5)

1.1.9 (2021-02-03)

Fixes

  • Support arrow functions without parameter parentheses in no-implicit-any-catch. (f4f4089)

1.1.8 (2021-01-11)

Changes

  • Fix GitHub URL to docs. (0add586)

1.1.7 (2020-11-28)

Changes

  • Use files in package.json instead of .npmignore. (5ace4c7)

1.1.6 (2020-11-03)

Changes

  • Update rule metadata.

1.1.5 (2020-10-28)

Changes

  • Removed no-misused-generics from the recommended set of rules. ATM, it's too likely that the rule will emit false-positive failures - see #15 and #24.

1.1.4 (2020-10-27)

Fixes

  • Include any signature type parameters in prefer-interface fixer output for function types. (aaebbd9)

1.1.3 (2020-10-27)

Fixes

  • Include type parameters in prefer-interface fixer output for function types. (8762605)

1.1.2 (2020-10-27)

Fixes

  • Include type parameters in prefer-interface fixer output. (d90b938)

1.1.1 (2020-10-27)

Changes

  • Specify Node 10 as the minimum engines in package.json and downlevel to ES2018.

1.1.0 (2020-10-26)

Features

  • Add the prefer-interface rule. (ccf6a02)

1.0.2 (2020-10-23)

Changes

  • Specify engines in package.json.
  • Downlevel the TypeScript output to ES2019.

1.0.1 (2020-10-22)

Changes

  • Update README.md.

1.0.0 (2020-10-22)

Breaking Changes

  • Remove deprecated rules.

Changes

  • Add rule docs.

0.0.3-beta.48 (2020-10-01)

Changes

  • A no-internal rule has been added.
  • The deprecation rule has been deprecated and renamed to no-deprecated.
  • The ban-imports rule has been deprecated in favour of the built-in ESLint rule no-restricted-imports.
  • The deprecated rules will be removed when the beta ends.

0.0.3-beta.46 (2020-09-25)

Breaking Changes

  • Removed the no-unused-declarations rule. Now that the official TypeScript ESLint plugin has a proper implementation of no-unused-vars, no-unused-declaration is pretty much redundant and I would prefer not to support it. If anyone needs to differentiate between vars and imports, the eslint-plugin-unused-imports plugin includes no-unused-vars-ts and no-unused-imports-ts rules - and the latter has a fixer.