npm.io
0.10.0 • Published 3 months ago

eslint-plugin-isotropic

Licence
BSD-3-Clause
Version
0.10.0
Deps
10
Size
124 kB
Vulns
0
Weekly
0
Stars
1

eslint-plugin-isotropic

npm version License

ESLint rules for Isotropic projects with sensible defaults and consistent conventions

Installation

You'll need ESLint v10.5.0 or above:

npm install eslint --save-dev

Next, install eslint-plugin-isotropic:

npm install eslint-plugin-isotropic --save-dev

Usage

Create an eslint.config.js file in your project root directory to use the isotropic configuration:

import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default [
    _eslintPluginIsotropic.configs.isotropic
];

Or if using CommonJS:

const _eslintPluginIsotropic = require('eslint-plugin-isotropic');

module.exports = [
    _eslintPluginIsotropic.configs.isotropic
];
Using Individual Rules

If you prefer to use only specific rules from the plugin without the entire preset:

import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/prefer-reflect-apply': 'error'
            // Add other rules as needed
        }
    }
]);

Features

This plugin provides a comprehensive set of rules and configurations:

Note: ESLint v10.x uses the "flat config" format (eslint.config.js). For more information, see the ESLint Configuration Files Documentation.

Custom Rules

array-literal-newline

Enforces consistent line breaks in array literals, and is automatically fixable with the --fix option. An empty array stays collapsed ([]); when every element is itself an array or object literal the elements "hug" the brackets, separated only by a comma and a space; and when any element is not an array or object literal, every element is placed on its own line.

This rule covers array literals only. Object literal formatting (each property on its own line, empty objects collapsed) is already handled by the object-curly-newline, object-property-newline, and object-curly-spacing rules, which the isotropic config enables. The behavior here cannot be reproduced with the @stylistic array rules, because they cannot express the "hugging" exception for arrays whose elements are all literals.

// ✅ Every element is a literal, so they hug the brackets
const a = [{
    a: 'a'
}, {
    b: 'b'
}];

// ✅ An element is not a literal, so every element is on its own line
const b = [
    {
        a: 'a'
    },
    someVariable
];

// ✅ Empty literals stay collapsed
const c = [{}, [], {}, []];

Configuration example:

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/array-literal-newline': 'error'
        }
    }
]);

See documentation for more details.

filename-must-match-pattern

Enforces filename naming conventions through a configurable regular expression pattern.

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/filename-must-match-pattern': ['warn', {
                pattern: '^[\\da-z](?:[\\d\\-.a-z]*?[\\da-z])?

See documentation for more details.

filename-must-not-match-pattern

Enforces that filenames do not match a specific pattern.

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/filename-must-not-match-pattern': ['warn', {
                pattern: '^index

See documentation for more details.

logger-error-property

Requires errors to be logged as the error property of the metadata object when using isotropic-logger, so that the logger's error serializer is applied. Only modules that import both isotropic-logger and isotropic-error are checked.

import _Error from 'isotropic-error';
import _logger from 'isotropic-logger';

// ❌ Incorrect
_logger.error(_Error({
    message: 'An error occurred'
}), 'An error occurred');

// ✅ Correct
_logger.error({
    error: _Error({
        message: 'An error occurred'
    })
}, 'An error occurred');

See documentation for more details.

no-unnecessary-return-await

Disallows return await (and the equivalent arrow body async () => await x) when the await is unnecessary, that is, when it is not inside a try block or a catch block of a try that has a finally. This rule is automatically fixable with the --fix option.

// ❌ Incorrect
const f = async () => {
    return await getValue();
};

// ✅ Correct
const f = async () => {
    return getValue();
};

See documentation for more details.

no-unnecessary-variable

Disallows a const whose value is read exactly once when inlining it cannot change behavior. Module-scoped constants, let/var, destructuring, values that mutate, and values that capture the current time are exempt.

// ❌ Incorrect
const getTwelve = () => {
    const twelve = 12;

    return twelve;
};

// ✅ Correct
const getTwelve = () => 12;

See documentation for more details.

prefer-reflect-apply

Encourages using Reflect.apply() over Function.prototype.apply() and Function.prototype.call(). This rule is automatically fixable with the --fix option.

// ❌ Incorrect
someFunction.call(object, ...args);
someFunction.apply(object, args);

// ✅ Correct
Reflect.apply(someFunction, object, args);

See documentation for more details.

sort-keys

Requires object keys to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in sort-keys rule with natural sorting options.

// ❌ Incorrect
const object = {
    c: 3,
    b: 2,
    a: 1
};

// ✅ Correct
const object = {
    a: 1,
    b: 2,
    c: 3
};

Configuration example:

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/sort-keys': ['error', {
                caseSensitive: false,
                direction: 'asc',
                ignoreSpecialCharacters: true,
                prefixPositions: { _: 'last' }
            }]
        }
    }
]);

Options:

  • caseSensitive: Whether sorting should be case-sensitive (default: false)
  • direction: Sort direction, either 'asc' or 'desc' (default: 'asc')
  • ignoreSpecialCharacters: Whether to ignore special characters during sorting (default: true)
  • prefixPositions: Define positions for prefixed keys (default: { _: 'last' })

See documentation for more details.

sort-vars

Requires variable declarations to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in sort-vars rule with natural sorting and handling of multiline declarations.

// ❌ Incorrect
const c = 3,
    b = 2,
    a = 1;

const {
    c,
    b,
    a
} = object;

// ✅ Correct
const a = 1,
    b = 2,
    c = 3;

const {
    a,
    b,
    c
} = object;

Configuration example:

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/sort-vars': ['error', {
                caseSensitive: false,
                direction: 'asc',
                ignoreSpecialCharacters: true,
                prefixPositions: {},
                strictEmptyLines: true
            }]
        }
    }
]);

Options:

  • caseSensitive: Whether sorting should be case-sensitive (default: false)
  • direction: Sort direction, either 'asc' or 'desc' (default: 'asc')
  • ignoreSpecialCharacters: Whether to ignore special characters during sorting (default: true)
  • prefixPositions: Define positions for prefixed variables (default: {})
  • strictEmptyLines: Whether to enforce rules about empty lines between variables (default: true)

See documentation for more details.

top-scope-prefix

Enforces that variables in the top scope of a module use a specific prefix, helping distinguish globals from local variables.

// ❌ Incorrect
const constVariable = null;
function functionVariable() {}

// ✅ Correct
const _constVariable = null;
function _functionVariable() {}

Configuration example:

// eslint.config.js
import { defineConfig } from "eslint/config";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default defineConfig([
    {
        files: ["**/*.js"],
        plugins: {
            isotropic: _eslintPluginIsotropic
        },
        rules: {
            'isotropic/top-scope-prefix': ['error', {
                prefix: '_'
            }]
        }
    }
]);

Options:

  • prefix: The prefix that must be used for top-scope variables (default: '_')

See documentation for more details.

Key Linting Decisions

Consistent Code Style

The plugin enforces a consistent code style through the Stylistic plugin, including:

  • Consistent indentation (4 spaces)
  • No semicolon-less code
  • Consistent spacing in code
  • Strict single quote preference for strings
  • Enforced curly braces for all blocks
Natural Sorting

For rules involving sorting (variables, object keys), the plugin uses isotropic-natural-sort which provides sensible ordering that matches human expectations.

Module Structure

The plugin encourages a clear module structure with:

  • Underscore-prefixed module-level variables to distinguish them from local variables
  • Consistent import ordering
  • Proper module export patterns
Modern JavaScript Features

The plugin encourages use of modern JavaScript features:

  • ES modules over CommonJS
  • Modern APIs like Reflect.apply() and Temporal (the Date global is disallowed in favor of Temporal)
  • Consistent use of ES6+ features

Combining with Other Configurations

You can combine the isotropic configuration with other configurations:

// eslint.config.js
import js from "@eslint/js";
import _eslintPluginIsotropic from 'eslint-plugin-isotropic';

export default [
    js.configs.recommended,
    _eslintPluginIsotropic.configs.isotropic,
    {
        files: ["**/*.js"],
        rules: {
            // Override specific rules
            "no-unused-vars": "warn"
        }
    }
];

Compatible ESLint Versions

This plugin requires ESLint 10.5.0 or later and uses ESLint's flat config system.

, flags: 'v' }] } } ]);

See documentation for more details.

__INLINE_CODE_11__

Enforces that filenames do not match a specific pattern.

__CODE_BLOCK_8__

See documentation for more details.

__INLINE_CODE_12__

Requires errors to be logged as the __INLINE_CODE_13__ property of the metadata object when using __INLINE_CODE_14__, so that the logger's error serializer is applied. Only modules that import both __INLINE_CODE_15__ and __INLINE_CODE_16__ are checked.

__CODE_BLOCK_9__

See documentation for more details.

__INLINE_CODE_17__

Disallows __INLINE_CODE_18__ (and the equivalent arrow body __INLINE_CODE_19__) when the __INLINE_CODE_20__ is unnecessary, that is, when it is not inside a __INLINE_CODE_21__ block or a __INLINE_CODE_22__ block of a __INLINE_CODE_23__ that has a __INLINE_CODE_24__. This rule is automatically fixable with the __INLINE_CODE_25__ option.

__CODE_BLOCK_10__

See documentation for more details.

__INLINE_CODE_26__

Disallows a __INLINE_CODE_27__ whose value is read exactly once when inlining it cannot change behavior. Module-scoped constants, __INLINE_CODE_28__/__INLINE_CODE_29__, destructuring, values that mutate, and values that capture the current time are exempt.

__CODE_BLOCK_11__

See documentation for more details.

__INLINE_CODE_30__

Encourages using __INLINE_CODE_31__ over __INLINE_CODE_32__ and __INLINE_CODE_33__. This rule is automatically fixable with the __INLINE_CODE_34__ option.

__CODE_BLOCK_12__

See documentation for more details.

__INLINE_CODE_35__

Requires object keys to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_36__ rule with natural sorting options.

__CODE_BLOCK_13__

Configuration example:

__CODE_BLOCK_14__

Options:

  • __INLINE_CODE_37__: Whether sorting should be case-sensitive (default: __INLINE_CODE_38__)
  • __INLINE_CODE_39__: Sort direction, either __INLINE_CODE_40__ or __INLINE_CODE_41__ (default: __INLINE_CODE_42__)
  • __INLINE_CODE_43__: Whether to ignore special characters during sorting (default: __INLINE_CODE_44__)
  • __INLINE_CODE_45__: Define positions for prefixed keys (default: __INLINE_CODE_46__)

See documentation for more details.

__INLINE_CODE_47__

Requires variable declarations to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_48__ rule with natural sorting and handling of multiline declarations.

__CODE_BLOCK_15__

Configuration example:

__CODE_BLOCK_16__

Options:

  • __INLINE_CODE_49__: Whether sorting should be case-sensitive (default: __INLINE_CODE_50__)
  • __INLINE_CODE_51__: Sort direction, either __INLINE_CODE_52__ or __INLINE_CODE_53__ (default: __INLINE_CODE_54__)
  • __INLINE_CODE_55__: Whether to ignore special characters during sorting (default: __INLINE_CODE_56__)
  • __INLINE_CODE_57__: Define positions for prefixed variables (default: __INLINE_CODE_58__)
  • __INLINE_CODE_59__: Whether to enforce rules about empty lines between variables (default: __INLINE_CODE_60__)

See documentation for more details.

__INLINE_CODE_61__

Enforces that variables in the top scope of a module use a specific prefix, helping distinguish globals from local variables.

__CODE_BLOCK_17__

Configuration example:

__CODE_BLOCK_18__

Options:

  • __INLINE_CODE_62__: The prefix that must be used for top-scope variables (default: __INLINE_CODE_63__)

See documentation for more details.

Key Linting Decisions

Consistent Code Style

The plugin enforces a consistent code style through the Stylistic plugin, including:

  • Consistent indentation (4 spaces)
  • No semicolon-less code
  • Consistent spacing in code
  • Strict single quote preference for strings
  • Enforced curly braces for all blocks
Natural Sorting

For rules involving sorting (variables, object keys), the plugin uses isotropic-natural-sort which provides sensible ordering that matches human expectations.

Module Structure

The plugin encourages a clear module structure with:

  • Underscore-prefixed module-level variables to distinguish them from local variables
  • Consistent import ordering
  • Proper module export patterns
Modern JavaScript Features

The plugin encourages use of modern JavaScript features:

  • ES modules over CommonJS
  • Modern APIs like __INLINE_CODE_64__ and __INLINE_CODE_65__ (the __INLINE_CODE_66__ global is disallowed in favor of __INLINE_CODE_67__)
  • Consistent use of ES6+ features

Combining with Other Configurations

You can combine the isotropic configuration with other configurations:

__CODE_BLOCK_19__

Compatible ESLint Versions

This plugin requires ESLint 10.5.0 or later and uses ESLint's flat config system.

, flags: 'v' }] } } ]);

See documentation for more details.

__INLINE_CODE_12__

Requires errors to be logged as the __INLINE_CODE_13__ property of the metadata object when using __INLINE_CODE_14__, so that the logger's error serializer is applied. Only modules that import both __INLINE_CODE_15__ and __INLINE_CODE_16__ are checked.

__CODE_BLOCK_9__

See documentation for more details.

__INLINE_CODE_17__

Disallows __INLINE_CODE_18__ (and the equivalent arrow body __INLINE_CODE_19__) when the __INLINE_CODE_20__ is unnecessary, that is, when it is not inside a __INLINE_CODE_21__ block or a __INLINE_CODE_22__ block of a __INLINE_CODE_23__ that has a __INLINE_CODE_24__. This rule is automatically fixable with the __INLINE_CODE_25__ option.

__CODE_BLOCK_10__

See documentation for more details.

__INLINE_CODE_26__

Disallows a __INLINE_CODE_27__ whose value is read exactly once when inlining it cannot change behavior. Module-scoped constants, __INLINE_CODE_28__/__INLINE_CODE_29__, destructuring, values that mutate, and values that capture the current time are exempt.

__CODE_BLOCK_11__

See documentation for more details.

__INLINE_CODE_30__

Encourages using __INLINE_CODE_31__ over __INLINE_CODE_32__ and __INLINE_CODE_33__. This rule is automatically fixable with the __INLINE_CODE_34__ option.

__CODE_BLOCK_12__

See documentation for more details.

__INLINE_CODE_35__

Requires object keys to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_36__ rule with natural sorting options.

__CODE_BLOCK_13__

Configuration example:

__CODE_BLOCK_14__

Options:

  • __INLINE_CODE_37__: Whether sorting should be case-sensitive (default: __INLINE_CODE_38__)
  • __INLINE_CODE_39__: Sort direction, either __INLINE_CODE_40__ or __INLINE_CODE_41__ (default: __INLINE_CODE_42__)
  • __INLINE_CODE_43__: Whether to ignore special characters during sorting (default: __INLINE_CODE_44__)
  • __INLINE_CODE_45__: Define positions for prefixed keys (default: __INLINE_CODE_46__)

See documentation for more details.

__INLINE_CODE_47__

Requires variable declarations to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_48__ rule with natural sorting and handling of multiline declarations.

__CODE_BLOCK_15__

Configuration example:

__CODE_BLOCK_16__

Options:

  • __INLINE_CODE_49__: Whether sorting should be case-sensitive (default: __INLINE_CODE_50__)
  • __INLINE_CODE_51__: Sort direction, either __INLINE_CODE_52__ or __INLINE_CODE_53__ (default: __INLINE_CODE_54__)
  • __INLINE_CODE_55__: Whether to ignore special characters during sorting (default: __INLINE_CODE_56__)
  • __INLINE_CODE_57__: Define positions for prefixed variables (default: __INLINE_CODE_58__)
  • __INLINE_CODE_59__: Whether to enforce rules about empty lines between variables (default: __INLINE_CODE_60__)

See documentation for more details.

__INLINE_CODE_61__

Enforces that variables in the top scope of a module use a specific prefix, helping distinguish globals from local variables.

__CODE_BLOCK_17__

Configuration example:

__CODE_BLOCK_18__

Options:

  • __INLINE_CODE_62__: The prefix that must be used for top-scope variables (default: __INLINE_CODE_63__)

See documentation for more details.

Key Linting Decisions

Consistent Code Style

The plugin enforces a consistent code style through the Stylistic plugin, including:

  • Consistent indentation (4 spaces)
  • No semicolon-less code
  • Consistent spacing in code
  • Strict single quote preference for strings
  • Enforced curly braces for all blocks
Natural Sorting

For rules involving sorting (variables, object keys), the plugin uses isotropic-natural-sort which provides sensible ordering that matches human expectations.

Module Structure

The plugin encourages a clear module structure with:

  • Underscore-prefixed module-level variables to distinguish them from local variables
  • Consistent import ordering
  • Proper module export patterns
Modern JavaScript Features

The plugin encourages use of modern JavaScript features:

  • ES modules over CommonJS
  • Modern APIs like __INLINE_CODE_64__ and __INLINE_CODE_65__ (the __INLINE_CODE_66__ global is disallowed in favor of __INLINE_CODE_67__)
  • Consistent use of ES6+ features

Combining with Other Configurations

You can combine the isotropic configuration with other configurations:

__CODE_BLOCK_19__

Compatible ESLint Versions

This plugin requires ESLint 10.5.0 or later and uses ESLint's flat config system.

, flags: 'v' }] } } ]);

See documentation for more details.

__INLINE_CODE_11__

Enforces that filenames do not match a specific pattern.

__CODE_BLOCK_8__

See documentation for more details.

__INLINE_CODE_12__

Requires errors to be logged as the __INLINE_CODE_13__ property of the metadata object when using __INLINE_CODE_14__, so that the logger's error serializer is applied. Only modules that import both __INLINE_CODE_15__ and __INLINE_CODE_16__ are checked.

__CODE_BLOCK_9__

See documentation for more details.

__INLINE_CODE_17__

Disallows __INLINE_CODE_18__ (and the equivalent arrow body __INLINE_CODE_19__) when the __INLINE_CODE_20__ is unnecessary, that is, when it is not inside a __INLINE_CODE_21__ block or a __INLINE_CODE_22__ block of a __INLINE_CODE_23__ that has a __INLINE_CODE_24__. This rule is automatically fixable with the __INLINE_CODE_25__ option.

__CODE_BLOCK_10__

See documentation for more details.

__INLINE_CODE_26__

Disallows a __INLINE_CODE_27__ whose value is read exactly once when inlining it cannot change behavior. Module-scoped constants, __INLINE_CODE_28__/__INLINE_CODE_29__, destructuring, values that mutate, and values that capture the current time are exempt.

__CODE_BLOCK_11__

See documentation for more details.

__INLINE_CODE_30__

Encourages using __INLINE_CODE_31__ over __INLINE_CODE_32__ and __INLINE_CODE_33__. This rule is automatically fixable with the __INLINE_CODE_34__ option.

__CODE_BLOCK_12__

See documentation for more details.

__INLINE_CODE_35__

Requires object keys to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_36__ rule with natural sorting options.

__CODE_BLOCK_13__

Configuration example:

__CODE_BLOCK_14__

Options:

  • __INLINE_CODE_37__: Whether sorting should be case-sensitive (default: __INLINE_CODE_38__)
  • __INLINE_CODE_39__: Sort direction, either __INLINE_CODE_40__ or __INLINE_CODE_41__ (default: __INLINE_CODE_42__)
  • __INLINE_CODE_43__: Whether to ignore special characters during sorting (default: __INLINE_CODE_44__)
  • __INLINE_CODE_45__: Define positions for prefixed keys (default: __INLINE_CODE_46__)

See documentation for more details.

__INLINE_CODE_47__

Requires variable declarations to be sorted in a consistent order. This rule extends the functionality of ESLint's built-in __INLINE_CODE_48__ rule with natural sorting and handling of multiline declarations.

__CODE_BLOCK_15__

Configuration example:

__CODE_BLOCK_16__

Options:

  • __INLINE_CODE_49__: Whether sorting should be case-sensitive (default: __INLINE_CODE_50__)
  • __INLINE_CODE_51__: Sort direction, either __INLINE_CODE_52__ or __INLINE_CODE_53__ (default: __INLINE_CODE_54__)
  • __INLINE_CODE_55__: Whether to ignore special characters during sorting (default: __INLINE_CODE_56__)
  • __INLINE_CODE_57__: Define positions for prefixed variables (default: __INLINE_CODE_58__)
  • __INLINE_CODE_59__: Whether to enforce rules about empty lines between variables (default: __INLINE_CODE_60__)

See documentation for more details.

__INLINE_CODE_61__

Enforces that variables in the top scope of a module use a specific prefix, helping distinguish globals from local variables.

__CODE_BLOCK_17__

Configuration example:

__CODE_BLOCK_18__

Options:

  • __INLINE_CODE_62__: The prefix that must be used for top-scope variables (default: __INLINE_CODE_63__)

See documentation for more details.

Key Linting Decisions

Consistent Code Style

The plugin enforces a consistent code style through the Stylistic plugin, including:

  • Consistent indentation (4 spaces)
  • No semicolon-less code
  • Consistent spacing in code
  • Strict single quote preference for strings
  • Enforced curly braces for all blocks
Natural Sorting

For rules involving sorting (variables, object keys), the plugin uses isotropic-natural-sort which provides sensible ordering that matches human expectations.

Module Structure

The plugin encourages a clear module structure with:

  • Underscore-prefixed module-level variables to distinguish them from local variables
  • Consistent import ordering
  • Proper module export patterns
Modern JavaScript Features

The plugin encourages use of modern JavaScript features:

  • ES modules over CommonJS
  • Modern APIs like __INLINE_CODE_64__ and __INLINE_CODE_65__ (the __INLINE_CODE_66__ global is disallowed in favor of __INLINE_CODE_67__)
  • Consistent use of ES6+ features

Combining with Other Configurations

You can combine the isotropic configuration with other configurations:

__CODE_BLOCK_19__

Compatible ESLint Versions

This plugin requires ESLint 10.5.0 or later and uses ESLint's flat config system.

Keywords