Skip to content

Latest commit

History

History
109 lines (85 loc) 路 2.82 KB

File metadata and controls

109 lines (85 loc) 路 2.82 KB

@babel/eslint-plugin-development-internal

The Babel team's custom ESLint rules for the babel/babel monorepo.

Installation

$ npm install --save-dev @babel/eslint-plugin-development-internal

or

$ yarn add --save-dev @babel/eslint-plugin-development-internal

Usage

The plugin can be loaded in your .eslintrc.* configuration file as follows: (note that you can omit the eslint-plugin- prefix):

{
  "plugins": ["@babel/development-internal"]
}

Rules

@babel/development-internal/dry-error-messages

Intended for use in packages/babel-parser/src/**/*. When enabled, this rule warns when this.raise() invocations raise errors that are not imported from a designated error module.

Accepts an object configuration option:

{
  errorModule: string
}

errorModule (required): The rule expects either an absolute path or a module name (for a module in node_modules). Please note that the rule will not check anything if errorModule is not given.

Example configuration:

{
  rules: {
    "@babel/development-internal/dry-error-messages": [
      "error",
      {
        errorModule: "@babel/shared-error-messages"
      }
    ]
  }
}

and

{
  rules: {
    "@babel/development-internal/dry-error-messages": [
      "error",
      {
        errorModule: path.resolve(
          __dirname,
          "packages/shared-error-messages/lib/index.js"
        )
      }
    ]
  }
}

@babel/development-internal/report-error-message-format

This rule is inspired by https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/report-message-format.md.

Intended for use in packages/babel-parser/src/**/*. When enabled, this rule warns for inconsistently error messages format in arguments of makeErrorTemplates function calls.

Basically, it starts with an uppercase Latin letter(A~Z) and ends with a period(.) or a question(?). But it can start with 'keyword' or `code` to include JavaScript keywords or code in error messages.

valid:

makeErrorTemplates({ ThisIsAnError: "This is an error." });
makeErrorTemplates({ ThisIsAnError: "'this' is an error." });
makeErrorTemplates({ ThisIsAnError: "`this` is an error." });
makeErrorTemplates({ ThisIsAnError: "This is an error?" });
makeErrorTemplates({ ThisIsAnError: "'this' is an error?" });
makeErrorTemplates({ ThisIsAnError: "`this` is an error?" });

invalid:

makeErrorTemplates({ ThisIsAnError: 'this is an error.' });
makeErrorTemplates({ ThisIsAnError: 'This is an error' });
makeErrorTemplates({ ThisIsAnError: 'this is an error?' });
makeErrorTemplates({ ThisIsAnError: '`this` is an error' });
makeErrorTemplates({ ThisIsAnError: "'this' is an error" });

Example configuration:

{
  rules: {
    "@babel/development-internal/report-error-message-format": "error"
  }
}