包详细信息

@rushstack/eslint-plugin

microsoft290.5kMIT0.18.0

An ESLint plugin providing supplementary rules for use with the @rushstack/eslint-config package

eslint, eslint-config, monorepo, rush

自述文件

@rushstack/eslint-plugin

This plugin implements supplementary rules for use with the @rushstack/eslint-config package, which provides a TypeScript ESLint ruleset tailored for large teams and projects. Please see that project's documentation for details. To learn about Rush Stack, please visit: https://rushstack.io/

@rushstack/hoist-jest-mock

Require Jest module mocking APIs to be called before any other statements in their code block.

Rule Details

Jest module mocking APIs such as "jest.mock()" must be called before the associated module is imported, otherwise they will have no effect. Transpilers such as ts-jest and babel-jest automatically "hoist" these calls, however this can produce counterintuitive behavior. Instead, the hoist-jest-mocks lint rule simply requires developers to write the statements in the correct order.

The following APIs are affected: 'jest.mock()', 'jest.unmock()', 'jest.enableAutomock()', 'jest.disableAutomock()', 'jest.deepUnmock()'.

For technical background, please read the Jest documentation here: https://jestjs.io/docs/en/es6-class-mocks

Examples

The following patterns are considered problems when @rushstack/hoist-jest-mock is enabled:

import * as file from './file'; // import statement
jest.mock('./file'); // error

test("example", () => {
  jest.mock('./file2'); // error
});
require('./file'); // import statement
jest.mock('./file'); // error

The following patterns are NOT considered problems:

jest.mock('./file'); // okay, because mock() precedes the import below
import * as file from './file'; // import statement
// These statements are not real "imports" because they import compile-time types
// without any runtime effects
import type { X } from './file';
let y: typeof import('./file');

jest.mock('./file'); // okay

@rushstack/no-new-null

Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null.

Rule Details

Most programming languages have a "null" or "nil" value that serves several purposes:

  1. the initial value for an uninitialized variable
  2. the value of x.y or x["y"] when x has no such key, and
  3. a special token that developers can assign to indicate an unknown or empty state.

In JavaScript, the undefined value fulfills all three roles. JavaScript's null value is a redundant secondary token that only fulfills (3), even though its name confusingly implies otherwise. The null value was arguably a mistake in the original JavaScript language design, but it cannot be banned entirely because it is returned by some entrenched system APIs such as JSON.parse(), and also some popular NPM packages. Thus, this rule aims to tolerate preexisting null values while preventing new ones from being introduced.

The @rushstack/no-new-null rule flags type definitions with null that can be exported or used by others. The rule ignores declarations that are local variables, private members, or types that are not exported.

If you are designing a new JSON file format, it's a good idea to avoid null entirely. In most cases there are better representations that convey more information about an item that is unknown, omitted, or disabled. If you do need to declare types for JSON structures containing null, rather than suppressing the lint rule, you can use a specialized JsonNull type as provided by @rushstack/node-core-library.

Examples

The following patterns are considered problems when @rushstack/no-new-null is enabled:

// interface declaration with null field
interface IHello { hello: null; } // error

// type declaration with null field
type Hello = { hello: null; } // error

// type function alias
type T = (args: string | null) => void; // error

// type alias
type N = null; // error

// type constructor
type C = {new (args: string | null)} // error

// function declaration with null args
function hello(world: string | null): void {}; // error
function legacy(callback: (err: Error| null) => void): void { }; // error

// function with null return type
function hello(): (err: Error | null) => void {}; // error

// const with null type
const nullType: 'hello' | null = 'hello'; // error

// classes with publicly visible properties and methods
class PublicNulls {
  property: string | null; // error
  propertyFunc: (val: string | null) => void; // error
  legacyImplicitPublic(hello: string | null): void {} // error
  public legacyExplicitPublic(hello: string | null): void {} // error
}

The following patterns are NOT considered problems:

// wrapping an null-API
export function ok(hello: string): void {
  const innerCallback: (err: Error | null) => void = (e) => {}; // passes
  return innerCallback(null);
}

// classes where null APIs are used, but are private-only
class PrivateNulls {
  private pField: string | null; // passes
  private pFunc: (val: string | null) => void; // passes
  private legacyPrivate(hello: string | null): void { // passes
    this.pField = hello;
    this.pFunc(this.pField)
    this.pFunc('hello')
  }
}

@rushstack/no-null

(Deprecated) Prevent usage of JavaScript's null keyword.

Rule Details

This rule has been superseded by @rushstack/no-new-null, and is maintained to support code that has not migrated to the new rule yet. The @rushstack/no-null rule prohibits null as a literal value, but allows it in type annotations. Comparisons with null are also allowed.

Examples

The following patterns are considered problems when @rushstack/no-null is enabled:

let x = null;  // error

f(null); // error

function g() {
    return null; // error
}

The following patterns are NOT considered problems:

let x: number | null = f(); // declaring types as possibly "null" is okay

if (x === null) {  // comparisons are okay
    x = 0;
}

@rushstack/no-untyped-underscore (Opt-in)

Prevent TypeScript code from accessing legacy JavaScript members whose name has an underscore prefix.

Rule Details

JavaScript does not provide a straightforward way to restrict access to object members, so API names commonly indicate a private member by using an underscore prefix (e.g. exampleObject._privateMember). For inexperienced developers who may be unfamiliar with this convention, in TypeScript we can mark the APIs as private or omit them from the typings. However, when migrating a large code base to TypeScript, it may be difficult to declare types for every legacy API. In this situation, the @rushstack/no-untyped-underscore rule can help.

This rule detects expressions that access a member with an underscore prefix, EXCEPT in cases where:

  • The object is typed: specifically, exampleObject has a TypeScript type that declares _privateMember; OR
  • The object expression uses: the this or super keywords; OR
  • The object expression is a variable named that. (In older ES5 code, that was commonly used as an alias for this in unbound contexts.)

Examples

The following patterns are considered problems when @rushstack/no-untyped-underscore is enabled:

let x: any;
x._privateMember = 123;  // error, because x is untyped

let x: { [key: string]: number };
x._privateMember = 123;  // error, because _privateMember is not a declared member of x's type

The following patterns are NOT considered problems:

let x: { _privateMember: any };
x._privateMember = 123;  // okay, because _privateMember is declared by x's type

let x = { _privateMember: 0 };
x._privateMember = 123;  // okay, because _privateMember is part of the inferred type

enum E {
    _PrivateMember
}
let e: E._PrivateMember = E._PrivateMember; // okay, because _PrivateMember is declared by E

Links

@rushstack/eslint-plugin is part of the Rush Stack family of projects.

更新日志

Change Log - @rushstack/eslint-plugin

This log was last generated on Tue, 11 Mar 2025 02:12:33 GMT and should not be manually modified.

0.18.0

Tue, 11 Mar 2025 02:12:33 GMT

Minor changes

  • Bump the @typescript-eslint/* packages to add support for TypeScript 5.8.

0.17.0

Sat, 01 Mar 2025 07:23:16 GMT

Minor changes

  • Bump the @typescript-eslint/* dependencies to ~8.24.0 to support newer versions of TypeScript.

0.16.1

Thu, 19 Sep 2024 00:11:08 GMT

Patches

  • Fix ESLint broken links

0.16.0

Wed, 14 Aug 2024 22:37:32 GMT

Minor changes

  • Add 4 new ESLint rules: "@rushstack/no-backslash-imports", used to prevent backslashes in import and require statements; "@rushstack/no-external-local-imports", used to prevent referencing external depedencies in import and require statements; "@rushstack/no-transitive-dependency-imports", used to prevent referencing transitive dependencies (ie. dependencies of dependencies) in import and require statements; and "@rushstack/normalized-imports", used to ensure that the most direct path to a dependency is provided in import and require statements

0.15.2

Sat, 27 Jul 2024 00:10:27 GMT

Patches

  • Include CHANGELOG.md in published releases again

0.15.1

Sat, 17 Feb 2024 06:24:34 GMT

Patches

  • Fix broken link to API documentation

0.15.0

Wed, 07 Feb 2024 01:11:18 GMT

Minor changes

  • Allow using as const in typedef-var

0.14.0

Tue, 16 Jan 2024 18:30:10 GMT

Minor changes

  • Add support for TypeScript 5.3 with @typescript-eslint 6.19.x

0.13.1

Tue, 26 Sep 2023 09:30:33 GMT

Version update only

0.13.0

Fri, 15 Sep 2023 00:36:58 GMT

Minor changes

  • Update @types/node from 14 to 18

0.12.0

Mon, 22 May 2023 06:34:32 GMT

Minor changes

  • Upgrade the @typescript-eslint/* dependencies to ~5.59.2

0.11.0

Thu, 29 Sep 2022 07:13:06 GMT

Minor changes

  • Upgraded @typescript-eslint dependencies to 5.30.x to enable support for TypeScript 4.8

0.10.0

Wed, 03 Aug 2022 18:40:35 GMT

Minor changes

  • Upgrade TypeScript dependency to 4.7

0.9.1

Fri, 17 Jun 2022 00:16:18 GMT

Version update only

0.9.0

Sat, 23 Apr 2022 02:13:06 GMT

Minor changes

  • Add support for TypeScript 4.6

0.8.6

Sat, 09 Apr 2022 02:24:26 GMT

Patches

  • Rename the "master" branch to "main".

0.8.5

Tue, 15 Mar 2022 19:15:53 GMT

Patches

  • Fix the path in the package.json "directory" field.

0.8.4

Mon, 06 Dec 2021 16:08:32 GMT

Patches

  • Add support for ESLint v8

0.8.3

Wed, 27 Oct 2021 00:08:15 GMT

Patches

  • Update the package.json repository field to include the directory property.

0.8.2

Thu, 07 Oct 2021 07:13:35 GMT

Patches

  • Update typescript-eslint to add support for TypeScript 4.4.

0.8.1

Thu, 23 Sep 2021 00:10:40 GMT

Patches

  • Upgrade the @types/node dependency to version to version 12.

0.8.0

Mon, 12 Jul 2021 23:08:26 GMT

Minor changes

  • Upgrade @typescript-eslint/* packages to 4.28.0 (GitHub #2389)

0.7.3

Tue, 06 Apr 2021 15:14:22 GMT

Patches

  • Fix unlisted dependency on @typescript-eslint/experimental-utils

0.7.2

Wed, 30 Sep 2020 18:39:17 GMT

Patches

  • Update to build with @rushstack/heft-node-rig

0.7.1

Wed, 30 Sep 2020 06:53:53 GMT

Patches

  • Include missing "License" field.
  • Update README.md

0.7.0

Tue, 22 Sep 2020 01:45:31 GMT

Minor changes

  • Add a new rule "@rushstack/typedef-var" which supplements "@typescript-eslint/typedef" by enabling a special policy for local variables

0.6.3

Sat, 19 Sep 2020 04:37:26 GMT

Patches

  • Add missing dependency

0.6.2

Sat, 19 Sep 2020 03:33:06 GMT

Patches

  • Extract the pattern matcher into the new "@rushstack/tree-pattern" package

0.6.1

Thu, 27 Aug 2020 11:27:06 GMT

Patches

  • Revise the "@rushstack/hoist-jest-mock" rule to allow some common Jest coding practices that are not problematic

0.6.0

Mon, 24 Aug 2020 07:35:20 GMT

Minor changes

  • Add new rule @rushstack/hoist-jest-mock

0.5.0

Sat, 22 Aug 2020 05:55:42 GMT

Minor changes

  • Add a new rule "@rushstack/no-new-null" that will replace "@rushstack/no-null"

0.4.2

Wed, 12 Aug 2020 00:10:05 GMT

Patches

  • Updated project to build with Heft

0.4.1

Wed, 24 Jun 2020 09:50:48 GMT

Patches

  • Fix an issue with the published file set

0.4.0

Wed, 24 Jun 2020 09:04:28 GMT

Minor changes

  • Upgrade to ESLint 7

0.3.2

Wed, 18 Mar 2020 15:07:47 GMT

Patches

  • Upgrade cyclic dependencies

0.3.1

Sun, 19 Jan 2020 02:26:53 GMT

Patches

  • Upgrade Node typings to Node 10

0.3.0

Fri, 17 Jan 2020 01:08:23 GMT

Minor changes

  • Allow null in == and != conditionals for no-null eslint rule

0.2.0

Thu, 09 Jan 2020 06:44:12 GMT

Minor changes

  • Add new rule @rushstack/no-untyped-underscore

0.1.0

Wed, 08 Jan 2020 00:11:31 GMT

Minor changes

  • Initial release