eslint-plugin-itgalaxy
Itgalaxy org's ESLint rules and configs.
Last updated 22 days ago by evilebottnawi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install eslint-plugin-itgalaxy 
SYNC missed versions from official npm registry.

eslint-plugin-itgalaxy

NPM version Build Status dependencies Status devDependencies Status peerDependencies Status

Itgalaxy’s ESLint rules and configs.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-itgalaxy:

$ npm install eslint-plugin-itgalaxy --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-itgalaxy globally.

Note: Some presets require additional dependencies (plugins). Example markdown require eslint-plugin-markdown plugin.

So you need run:

$ npm install eslint-plugin-markdown --save-dev

By default all additional plugins listed in peerDependencies (this allows you to track non-compatibility with old versions), just ignore warnings if you don't need a plugin.

Usage

Itgalaxy’s ESLint configs come bundled in this package. In order to use them, you simply extend the relevant configuration in your project’s .eslintrc.

Configurations do not contain stylistic rules, we use prettier for this purpose.

Better use prettier directly (using npm/yarn command), because it is allow to format css, scss, markdown, json and etc.

For example, the following will extend the ESNext (ES2015 and later) config:

module.exports = {
  extends: [
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
};

If using React, extend the React version of the configuration (which adds some React-specific rules to those in the ESNext config):

module.exports = {
  extends: [
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/react",
  ],
};

Provided configurations

This plugin provides the following core configurations:

Example of configuration:

{
  "extends": ["plugin:itgalaxy/script"]
}

Example of configuration:

{
  "extends": ["plugin:itgalaxy/module"]
}

Example of configuration:

{
  "extends": ["plugin:itgalaxy/dirty"]
}

Why? Very often you are faced with writing or having code using ECMAScript and CommonJS modules, you should use this preset in this case.

Example of configuration:

import eslint from "eslint";

/**
 * @param {string} configName Config name
 * @returns {object} Config
 */
function loadConfig(configName) {
  // eslint-disable-next-line node/global-require, import/no-dynamic-require
  return require(`my-${configName}`);
}

console.log(__dirname);
console.log(__filename);
console.log(import.meta.url);

loadConfig("example");
  • esnext: use this for anything written with ES2015+ features.

Contains most of the rules for linting code. Does not contain environments for CommonJS and ECMA modules and rules for require/import/export/etc.

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
  ],
};
  • node: use this for Node.js projects.

Preset contains environment and rules for Node.js code.

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/script",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
};
  • browser: use this for browser projects.

Preset contains environment and rules for browser code.

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/browser",
  ],
};
  • react: Use this for React projects.

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/react",
  ],
};
  • html: Allow linting JavaScript in HTML (and HTML based) files (don't forget add .html to --ext CLI argument).

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/module",
    // You can use "plugin:itgalaxy/node"
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/html",
  ],
};

Don't forget to add --ext ".js,.html for CLI usage.

  • markdown: Allow linting JavaScript in markdown files (don't forget add .md to --ext CLI argument).

Example of configuration:

module.exports = {
  extends: [
    // You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
    "plugin:itgalaxy/dirty",
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/node" or use them both
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/markdown",
  ],
};

Don't forget to add --ext ".js,.md for CLI usage.

  • all: Don't use. It is for internal purposes (testings and tools).

This plugin also provides the following tool-specific configurations, which can be used on top of the core configurations:

  • AVA: Use this for projects that use the AVA.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/ava",
  ],
};
  • Jest: Use this for projects that use the Jest.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/jest",
  ],
};

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/lodash",
  ],
};

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/jsdoc-typescript",
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
};

Examples

CommonJS package for Node.js

.eslintrc.js

"use strict";

module.exports = {
  extends: [
    "plugin:itgalaxy/script",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
  overrides: [
    // Tests
    {
      extends: ["plugin:itgalaxy/jest"],
      excludedFiles: ["**/*.md"],
      files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
      rules: {
        // Allow to use `console` (example - `mocking`)
        "no-console": "off",
      },
    },

    // Markdown
    {
      extends: [
        // Documentation files can contain ES module syntax and CommonJS module syntax
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/markdown",
      ],
      files: ["**/*.md"],
      rules: {
        "no-unused-vars": "off",
        "no-console": "off",
        "import/no-unresolved": "off",
        "node/no-unpublished-require": "off",
        "node/no-unpublished-import": "off",
        // Documentation files can contain ES module syntax and CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },
  ],
  root: true,
};

ECMA package for Node.js

.eslintrc.js

"use strict";

module.exports = {
  extends: [
    // You can change this on `"plugin:itgalaxy/dirty" or `"plugin:itgalaxy/module"` if you use `node-babel` or use ECMA modules for config files (like `.eslint.js`/`prettier.config.js`/etc)
    "plugin:itgalaxy/script",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
  overrides: [
    // Source
    {
      extends: ["plugin:itgalaxy/module"],
      // Exclude nested tests
      excludedFiles: ["**/__tests__/**/*", "**/__mocks__/**/*", "**/*.md"],
      files: ["src/**/*"],
      rules: {
        // Allow to use ES module syntax
        // You should use babel if your node version is not supported ES syntax module, dynamic loading ES modules or other features
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },

    // Jest
    {
      extends: ["plugin:itgalaxy/module", "plugin:itgalaxy/jest"],
      excludedFiles: ["**/*.md"],
      files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
      rules: {
        // Test can be written with using ES module syntax or CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],

        // Allow to use `console` (example - `mocking`)
        "no-console": "off",
      },
    },

    // Markdown
    {
      extends: [
        // Documentation files can contain ECMA and CommonJS modules
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/markdown",
      ],
      files: ["**/*.md"],
      rules: {
        "no-unused-vars": "off",
        "no-console": "off",
        "import/no-unresolved": "off",
        "node/no-unpublished-require": "off",
        "node/no-unpublished-import": "off",
        // Documentation files can contain ES module syntax and CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },
  ],
  root: true,
};

ECMA and CommonJS in one package for Node.js

.eslintrc.js

"use strict";

module.exports = {
  extends: [
    // You can change this on `"plugin:itgalaxy/dirty" or `"plugin:itgalaxy/module"` if you use `node-babel` or use ECMA modules for config files (like `.eslint.js`/`prettier.config.js`/etc)
    "plugin:itgalaxy/script",
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/node",
  ],
  overrides: [
    // Source
    {
      extends: ["plugin:itgalaxy/dirty"],
      // Exclude nested tests
      excludedFiles: ["**/__tests__/**/*", "**/__mocks__/**/*", "**/*.md"],
      files: ["src/**/*"],
      rules: {
        // Allow to use ES module syntax
        // You should use babel if your node version is not supported ES syntax module, dynamic loading ES modules or other features
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },

    // Jest
    {
      extends: ["plugin:itgalaxy/dirty", "plugin:itgalaxy/jest"],
      excludedFiles: ["**/*.md"],
      files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
      rules: {
        // Test can be written with using ES module syntax or CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],

        // Allow to use `console` (example - `mocking`)
        "no-console": "off",
      },
    },

    // Markdown
    {
      extends: [
        // Documentation files can contain ECMA and CommonJS modules
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/markdown",
      ],
      files: ["**/*.md"],
      rules: {
        "no-unused-vars": "off",
        "no-console": "off",
        "import/no-unresolved": "off",
        "node/no-unpublished-require": "off",
        "node/no-unpublished-import": "off",
        // Documentation files can contain ES module syntax and CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },
  ],
  root: true,
};

Browser package with ECMA modules

.eslintrc.js

"use strict";

module.exports = {
  extends: [
    // You can change this on `"plugin:itgalaxy/dirty" or `"plugin:itgalaxy/module" if you use `node-babel` or use ECMA modules for config file (like `.eslint.js`/`prettier.config.js`/etc)
    "plugin:itgalaxy/script",
    "plugin:itgalaxy/esnext",
  ],
  overrides: [
    // Source
    {
      extends: ["plugin:itgalaxy/module", "plugin:itgalaxy/browser"],
      // Exclude nested tests
      excludedFiles: ["**/__tests__/**/*", "**/__mocks__/**/*", "**/*.md"],
      files: ["src/**/*"],
    },

    // Jest
    {
      extends: [
        "plugin:itgalaxy/module",
        "plugin:itgalaxy/node",
        "plugin:itgalaxy/jest",
      ],
      excludedFiles: ["**/*.md"],
      files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
      rules: {
        // Test can be written with using ES module syntax or CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],

        // Allow to use `console` (example - `mocking`)
        "no-console": "off",
      },
    },

    // Markdown
    {
      extends: [
        // Documentation files can contain ECMA and CommonJS modules
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/markdown",
      ],
      files: ["**/*.md"],
      rules: {
        "no-unused-vars": "off",
        "no-console": "off",
        "import/no-unresolved": "off",
        "node/no-unpublished-require": "off",
        "node/no-unpublished-import": "off",
        // Documentation files can contain ES module syntax and CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },
  ],
  root: true,
};

Application with ECMA modules and react

"use strict";

module.exports = {
  extends: ["plugin:itgalaxy/esnext"],
  overrides: [
    // Source
    {
      extends: [
        // Allow to use `import` and `require`
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/browser",
        "plugin:itgalaxy/react",
      ],
      env: {
        // Do you use `jquery`?
        // jquery: true
      },
      // Exclude nested tests
      excludedFiles: ["**/__tests__/**/*", "**/__mocks__/**/*", "**/*.md"],
      files: ["src/**/*"],
      globals: {
        // If you use `process.env.NODE_ENV` in your source code using webpack
        process: true,
      },
      rules: {
        // Disable `require()` in favor `import` on front-end
        "import/no-commonjs": "error",
        // No `process.exit()` on front-end
        "no-process-exit": "error",
      },
      settings: {
        "import/resolver": {
          webpack: {
            config: require.resolve("./webpack.config.js"),
          },
        },
      },
    },

    // Configurations and Node.js code
    {
      extends: ["plugin:itgalaxy/script", "plugin:itgalaxy/node"],
      excludedFiles: [
        "src/**/*",
        "**/__tests__/**/*",
        "**/__mocks__/**/*",
        "**/*.md",
      ],
      // All locations exclude sources and tests
      files: [".*.*", "**/*"],
      rules: {
        "no-console": "off",
      },
    },

    // Jest
    {
      extends: [
        "plugin:itgalaxy/module",
        "plugin:itgalaxy/node",
        "plugin:itgalaxy/browser",
        "plugin:itgalaxy/react",
        "plugin:itgalaxy/jest",
      ],
      excludedFiles: ["**/*.md"],
      files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
      rules: {
        // Test can be written with using ES module syntax or CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],

        // Allow to use Node.js modules
        "import/no-nodejs-modules": "off",

        // Allow to use `console` (for example - `mocking`)
        "no-console": "off",
      },
    },

    // Markdown
    {
      extends: [
        // Documentation files can contain ECMA and CommonJS modules
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/node",
        "plugin:itgalaxy/browser",
        "plugin:itgalaxy/react",
        "plugin:itgalaxy/markdown",
      ],
      files: ["**/*.md"],
      rules: {
        "no-unused-vars": "off",
        "no-console": "off",
        "import/no-unresolved": "off",
        "node/no-unpublished-require": "off",
        "node/no-unpublished-import": "off",
        // Test can be written with using ES module syntax or CommonJS module syntax
        "node/no-unsupported-features/es-syntax": [
          "error",
          { ignores: ["modules", "dynamicImport"] },
        ],
      },
    },
  ],
  root: true,
};

Changelog

License

Current Tags

  • 129.0.0                                ...           latest (22 days ago)

155 Versions

  • 129.0.0                                ...           22 days ago
  • 128.0.0                                ...           a month ago
  • 127.0.0                                ...           2 months ago
  • 126.0.0                                ...           6 months ago
  • 125.0.1                                ...           7 months ago
  • 125.0.0                                ...           7 months ago
  • 124.0.0                                ...           7 months ago
  • 123.0.0                                ...           8 months ago
  • 122.0.0                                ...           9 months ago
  • 121.0.0                                ...           9 months ago
  • 120.0.0                                ...           9 months ago
  • 119.0.0                                ...           10 months ago
  • 118.0.0                                ...           10 months ago
  • 117.0.0                                ...           a year ago
  • 116.0.0                                ...           a year ago
  • 115.0.0                                ...           a year ago
  • 114.0.0                                ...           a year ago
  • 113.0.0                                ...           a year ago
  • 112.0.0                                ...           a year ago
  • 111.0.0                                ...           a year ago
  • 110.0.0                                ...           a year ago
  • 109.0.0                                ...           a year ago
  • 108.0.0                                ...           a year ago
  • 107.0.0                                ...           a year ago
  • 106.0.0                                ...           a year ago
  • 105.0.0                                ...           a year ago
  • 104.0.0                                ...           a year ago
  • 103.0.0                                ...           a year ago
  • 102.0.0                                ...           a year ago
  • 101.0.0                                ...           a year ago
  • 100.0.0                                ...           2 years ago
  • 99.0.0                                ...           2 years ago
  • 98.0.0                                ...           2 years ago
  • 97.0.1                                ...           2 years ago
  • 97.0.0                                ...           2 years ago
  • 96.0.0                                ...           2 years ago
  • 95.0.0                                ...           2 years ago
  • 94.0.0                                ...           2 years ago
  • 93.0.0                                ...           2 years ago
  • 92.0.1                                ...           2 years ago
  • 92.0.0                                ...           2 years ago
  • 91.1.0                                ...           2 years ago
  • 91.0.0                                ...           2 years ago
  • 90.0.0                                ...           2 years ago
  • 89.0.0                                ...           2 years ago
  • 88.0.0                                ...           2 years ago
  • 87.0.0                                ...           2 years ago
  • 86.0.0                                ...           2 years ago
  • 85.0.0                                ...           2 years ago
  • 84.0.0                                ...           2 years ago
  • 83.0.0                                ...           2 years ago
  • 82.0.0                                ...           2 years ago
  • 81.0.0                                ...           2 years ago
  • 80.0.0                                ...           2 years ago
  • 79.0.0                                ...           2 years ago
  • 78.0.0                                ...           2 years ago
  • 77.0.0                                ...           2 years ago
  • 76.0.0                                ...           2 years ago
  • 75.0.0                                ...           2 years ago
  • 74.0.0                                ...           2 years ago
  • 73.0.0                                ...           2 years ago
  • 72.0.0                                ...           2 years ago
  • 71.0.0                                ...           2 years ago
  • 70.0.1                                ...           2 years ago
  • 70.0.0                                ...           2 years ago
  • 69.0.0                                ...           2 years ago
  • 68.0.1                                ...           2 years ago
  • 68.0.0                                ...           2 years ago
  • 67.0.0                                ...           3 years ago
  • 66.0.0                                ...           3 years ago
  • 65.0.0                                ...           3 years ago
  • 64.0.0                                ...           3 years ago
  • 63.0.0                                ...           3 years ago
  • 62.0.0                                ...           3 years ago
  • 61.0.0                                ...           3 years ago
  • 60.0.0                                ...           3 years ago
  • 59.0.0                                ...           3 years ago
  • 58.0.0                                ...           3 years ago
  • 57.0.0                                ...           3 years ago
  • 56.0.0                                ...           3 years ago
  • 55.0.0                                ...           3 years ago
  • 54.0.0                                ...           3 years ago
  • 53.0.0                                ...           3 years ago
  • 52.0.0                                ...           3 years ago
  • 51.0.0                                ...           3 years ago
  • 50.0.0                                ...           3 years ago
  • 49.0.0                                ...           3 years ago
  • 48.0.0                                ...           3 years ago
  • 47.0.0                                ...           3 years ago
  • 46.0.0                                ...           3 years ago
  • 45.0.0                                ...           4 years ago
  • 44.0.0                                ...           4 years ago
  • 43.0.0                                ...           4 years ago
  • 42.0.0                                ...           4 years ago
  • 41.0.0                                ...           4 years ago
  • 40.0.0                                ...           4 years ago
  • 39.0.0                                ...           4 years ago
  • 38.0.0                                ...           4 years ago
  • 37.0.0                                ...           4 years ago
  • 36.0.0                                ...           4 years ago
  • 35.0.0                                ...           4 years ago
  • 34.0.0                                ...           4 years ago
  • 33.0.0                                ...           4 years ago
  • 32.0.0                                ...           4 years ago
  • 31.0.0                                ...           4 years ago
  • 30.0.0                                ...           4 years ago
  • 29.0.0                                ...           4 years ago
  • 28.0.0                                ...           4 years ago
  • 27.0.0                                ...           4 years ago
  • 26.0.0                                ...           4 years ago
  • 25.0.0                                ...           4 years ago
  • 24.0.0                                ...           4 years ago
  • 23.0.0                                ...           4 years ago
  • 22.0.0                                ...           4 years ago
  • 21.0.0                                ...           4 years ago
  • 20.0.2                                ...           4 years ago
  • 20.0.1                                ...           4 years ago
  • 20.0.0                                ...           4 years ago
  • 19.0.0                                ...           4 years ago
  • 18.0.0                                ...           4 years ago
  • 17.0.0                                ...           4 years ago
  • 16.0.0                                ...           4 years ago
  • 15.0.1                                ...           4 years ago
  • 15.0.0                                ...           4 years ago
  • 14.0.0                                ...           4 years ago
  • 13.0.0                                ...           4 years ago
  • 12.0.0                                ...           4 years ago
  • 11.0.1                                ...           4 years ago
  • 11.0.0                                ...           4 years ago
  • 10.0.2                                ...           4 years ago
  • 10.0.1                                ...           4 years ago
  • 10.0.0                                ...           4 years ago
  • 9.0.0                                ...           4 years ago
  • 8.0.0                                ...           4 years ago
  • 7.0.1                                ...           4 years ago
  • 7.0.0                                ...           4 years ago
  • 6.0.0                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.5                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 34
Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |