138.0.0 • Published 2 years ago

eslint-plugin-itgalaxy v138.0.0

Weekly downloads
78
License
MIT
Repository
github
Last release
2 years ago

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 (ES2020 and later) config:

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

React:

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

Provided configurations

This plugin provides the following core configurations:

  • script: preset for environment without require/import (old browsers or custom env).

Example of configuration:

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

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, for example babel allows you to do it, you should use this preset in this case. But it is not recommended. Prefer to use plugin:itgalaxy/module.

More information about dirty (unambiguous).

Example of dirty (unambiguous) code:

import eslint from "eslint";

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

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

loadConfig("example");
  • node: use this for Node.js projects (preset contains only environments rules, i.e. no rules for require/import, see above presets).

Preset contains environment and rules for Node.js code.

Example of configuration:

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

Preset contains environment and rules for browser code.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
  ],
};
  • esnext: use this for anything written with ES2015+ features.

Contains most of the rules for linting code.

Does not contain rules for CommonJS and ECMA modules syntax, rules for require/import/module.export/exports/etc and environments (i.e. browser/node/etc).

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
  ],
};
  • react: Use this for react projects.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/react",
  ],
};
  • html: Allow linting JavaScript in HTML (and HTML based) files.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/html",
  ],
};
  • markdown: Allow linting JavaScript in markdown files.

By default allows you to use import and require in documentation. Also, all rules are related to no-unresolved/no-unused/unpublished are disabled by default and you can use console.log(something).

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/markdown",
  ],
};
  • AVA: Use this for projects that use the AVA.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/ava",
  ],
};
  • Jest: Use this for projects that use the Jest.

Please read this ecmascript-modules for using jest with ECMA modules.

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/browser",
    "plugin:itgalaxy/jest",
  ],
};

Example of configuration:

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
    "plugin:itgalaxy/module",
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/jsdoc-typescript",
  ],
};

Examples

CommonJS

.eslintrc.js

"use strict";

module.exports = {
  extends: [
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/commonjs",
    // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler)
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/jest",
    // Lint documentation
    "plugin:itgalaxy/markdown",
    // Uncomment to use jsdoc typescript
    // "plugin:itgalaxy/jsdoc-typescript",
  ],
  root: true,
};

ECMA modules

.eslintrc.js

export default {
  extends: [
    "plugin:itgalaxy/esnext",
    // You can change this on "plugin:itgalaxy/dirty" if you use `node-babel`, bundler and have mixed code with `import` and `require`
    "plugin:itgalaxy/module",
    // Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler)
    "plugin:itgalaxy/node",
    "plugin:itgalaxy/jest",
    // Lint documentation
    "plugin:itgalaxy/markdown",
    // Uncomment to use jsdoc typescript
    // "plugin:itgalaxy/jsdoc-typescript",
  ],
  root: true,
};

Application with ECMA modules and react

"use strict";

module.exports = {
  // You can use "plugin:itgalaxy/module" and remove "plugin:itgalaxy/module", "plugin:itgalaxy/dirty" and "plugin:itgalaxy/script"
  // if you use ECMA modules everywhere (preferable)
  // Configuration files and scripts
  extends: [
    "plugin:itgalaxy/esnext",
    "plugin:itgalaxy/commonjs",
    "plugin:itgalaxy/jest",
    // Lint documentation
    "plugin:itgalaxy/markdown",
    // Uncomment to use jsdoc typescript
    // "plugin:itgalaxy/jsdoc-typescript",
  ],
  overrides: [
    // Source code of application
    {
      files: ["src/**/*.[jt]s?(x)"],
      extends: [
        "plugin:itgalaxy/module",
        "plugin:itgalaxy/browser",
        "plugin:itgalaxy/react",
      ],
      env: {
        // Do you use `jquery`?
        // jquery: true
      },
    },
    // Tests and documentation
    {
      files: [
        "**/{tests,test,__tests__}/**/*.[jt]s?(x)",
        "**/?(*.)+(spec|test).[jt]s?(x)",
        "**/test-*.[jt]s?(x)",
        "**/*.{md,markdown,mdown,mkdn,mkd,mdwn,mkdown,ron}/**",
      ],
      extends: [
        "plugin:itgalaxy/dirty",
        "plugin:itgalaxy/node",
        "plugin:itgalaxy/browser",
        "plugin:itgalaxy/react",
      ],
    },
  ],
  root: true,
};

Changelog

License

138.0.0

2 years ago

137.0.0

2 years ago

136.0.0

2 years ago

135.0.0

3 years ago

134.0.0

3 years ago

133.0.0

3 years ago

132.0.0

3 years ago

130.0.0

3 years ago

131.0.0

3 years ago

129.0.0

4 years ago

128.0.0

4 years ago

127.0.0

4 years ago

126.0.0

4 years ago

125.0.1

4 years ago

125.0.0

4 years ago

124.0.0

4 years ago

123.0.0

4 years ago

122.0.0

4 years ago

121.0.0

4 years ago

120.0.0

4 years ago

119.0.0

4 years ago

118.0.0

4 years ago

117.0.0

4 years ago

116.0.0

4 years ago

115.0.0

4 years ago

114.0.0

5 years ago

113.0.0

5 years ago

112.0.0

5 years ago

111.0.0

5 years ago

110.0.0

5 years ago

109.0.0

5 years ago

108.0.0

5 years ago

107.0.0

5 years ago

106.0.0

5 years ago

105.0.0

5 years ago

104.0.0

5 years ago

103.0.0

5 years ago

102.0.0

5 years ago

101.0.0

5 years ago

100.0.0

5 years ago

99.0.0

5 years ago

98.0.0

5 years ago

97.0.1

5 years ago

97.0.0

5 years ago

96.0.0

5 years ago

95.0.0

5 years ago

94.0.0

5 years ago

93.0.0

5 years ago

92.0.1

5 years ago

92.0.0

5 years ago

91.1.0

5 years ago

91.0.0

5 years ago

90.0.0

5 years ago

89.0.0

5 years ago

88.0.0

5 years ago

87.0.0

6 years ago

86.0.0

6 years ago

85.0.0

6 years ago

84.0.0

6 years ago

83.0.0

6 years ago

82.0.0

6 years ago

81.0.0

6 years ago

80.0.0

6 years ago

79.0.0

6 years ago

78.0.0

6 years ago

77.0.0

6 years ago

76.0.0

6 years ago

75.0.0

6 years ago

74.0.0

6 years ago

73.0.0

6 years ago

72.0.0

6 years ago

71.0.0

6 years ago

70.0.1

6 years ago

70.0.0

6 years ago

69.0.0

6 years ago

68.0.1

6 years ago

68.0.0

6 years ago

67.0.0

6 years ago

66.0.0

6 years ago

65.0.0

6 years ago

64.0.0

6 years ago

63.0.0

6 years ago

62.0.0

6 years ago

61.0.0

6 years ago

60.0.0

6 years ago

59.0.0

6 years ago

58.0.0

6 years ago

57.0.0

7 years ago

56.0.0

7 years ago

55.0.0

7 years ago

54.0.0

7 years ago

53.0.0

7 years ago

52.0.0

7 years ago

51.0.0

7 years ago

50.0.0

7 years ago

49.0.0

7 years ago

48.0.0

7 years ago

47.0.0

7 years ago

46.0.0

7 years ago

45.0.0

7 years ago

44.0.0

7 years ago

43.0.0

7 years ago

42.0.0

7 years ago

41.0.0

7 years ago

40.0.0

7 years ago

39.0.0

7 years ago

38.0.0

7 years ago

37.0.0

7 years ago

36.0.0

7 years ago

35.0.0

7 years ago

34.0.0

7 years ago

33.0.0

7 years ago

32.0.0

7 years ago

31.0.0

7 years ago

30.0.0

7 years ago

29.0.0

7 years ago

28.0.0

7 years ago

27.0.0

7 years ago

26.0.0

8 years ago

25.0.0

8 years ago

24.0.0

8 years ago

23.0.0

8 years ago

22.0.0

8 years ago

21.0.0

8 years ago

20.0.2

8 years ago

20.0.1

8 years ago

20.0.0

8 years ago

19.0.0

8 years ago

18.0.0

8 years ago

17.0.0

8 years ago

16.0.0

8 years ago

15.0.1

8 years ago

15.0.0

8 years ago

14.0.0

8 years ago

13.0.0

8 years ago

12.0.0

8 years ago

11.0.1

8 years ago

11.0.0

8 years ago

10.0.2

8 years ago

10.0.1

8 years ago

10.0.0

8 years ago

9.0.0

8 years ago

8.0.0

8 years ago

7.0.1

8 years ago

7.0.0

8 years ago

6.0.0

8 years ago

5.0.0

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago