Skip to content

Commit

Permalink
refactor: script and commonjs presets
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 17, 2021
1 parent 4bf1c4f commit c5cf28c
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
extends: [
"./lib/config/script.js",
"./lib/config/commonjs.js",
"./lib/config/node.js",
"./lib/config/esnext.js",
"./lib/config/jsdoc-typescript.js",
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ rule (it is breaking changed by default).

## 134.0.0 - 2021-09-17

- Changed: minimum required `eslint` version is `^7.32.0`
- Added: `commonjs` preset (before it was the `script` preset).
- Changed: `script` preset is now just `script`.
- Changed: minimum required `eslint` version is `^7.32.0`.
- Changed: minimum required `eslint-plugin-import` version is now `2.24.2`.
- Changed: minimum required `eslint-plugin-markdown` version is now `2.2.1`.
- Changed: minimum required `eslint-plugin-jest` version is now `24.4.2`.
Expand Down
71 changes: 39 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@ module.exports = {

This plugin provides the following core configurations:

- [script](lib/config/script.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc).
- [script](lib/config/script.js): preset for environment without `require`/`import` (old browsers or custom env).

Example of configuration:

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

- [commonjs](lib/config/commonjs.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc).

Example of configuration:

Expand Down Expand Up @@ -129,7 +139,7 @@ console.log(import.meta.url);
loadConfig("example");
```
- [node](lib/config/node.js): use this for `Node.js` projects.
- [node](lib/config/node.js): 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.
Expand All @@ -138,9 +148,9 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/module",
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/module",
"plugin:itgalaxy/node",
],
};
Expand All @@ -155,9 +165,9 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/module",
"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",
],
};
Expand All @@ -174,9 +184,9 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/module",
"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",
],
};
```
Expand All @@ -188,10 +198,10 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
"plugin:itgalaxy/module",
"plugin:itgalaxy/browser",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/react",
],
};
Expand All @@ -204,10 +214,10 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
"plugin:itgalaxy/module",
"plugin:itgalaxy/browser",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/html",
],
};
Expand All @@ -223,11 +233,10 @@ Example of configuration:
```js
module.exports = {
extends: [
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
"plugin:itgalaxy/module",
// You can use "plugin:itgalaxy/node" or use them both
"plugin:itgalaxy/browser",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/markdown",
],
};
Expand All @@ -240,10 +249,10 @@ Example of configuration:
```js
module.exports = {
extends: [
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
"plugin:itgalaxy/module",
// You can use "plugin:itgalaxy/node" or use them both
"plugin:itgalaxy/browser",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/ava",
],
};
Expand All @@ -258,10 +267,10 @@ Example of configuration:
```js
module.exports = {
extends: [
"plugin:itgalaxy/esnext",
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
"plugin:itgalaxy/module",
// You can use "plugin:itgalaxy/node" or use them both
"plugin:itgalaxy/browser",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/jest",
],
};
Expand All @@ -274,9 +283,10 @@ Example of configuration:
```js
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/esnext",
"plugin:itgalaxy/jsdoc-typescript",
],
};
Expand All @@ -293,10 +303,10 @@ module.exports = {

module.exports = {
extends: [
"plugin:itgalaxy/script",
// Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments
"plugin:itgalaxy/node",
"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",
Expand All @@ -314,11 +324,11 @@ module.exports = {
```js
export default {
extends: [
// You can change this on "plugin:itgalaxy/dirty" if you use `node-babel` and have mixed code with `import` and `require`
"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
// 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/esnext",
"plugin:itgalaxy/jest",
// Lint documentation
"plugin:itgalaxy/markdown",
Expand All @@ -339,9 +349,9 @@ module.exports = {
// if you use ECMA modules everywhere (preferable)
// Configuration files and scripts
extends: [
"plugin:itgalaxy/script",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/ava",
"plugin:itgalaxy/commonjs",
"plugin:itgalaxy/jest",
// Lint documentation
"plugin:itgalaxy/markdown",
// Uncomment to use jsdoc typescript
Expand All @@ -350,6 +360,7 @@ module.exports = {
overrides: [
// Source code of application
{
files: ["src/**/*.[jt]s?(x)"],
extends: [
"plugin:itgalaxy/module",
"plugin:itgalaxy/browser",
Expand All @@ -359,7 +370,6 @@ module.exports = {
// Do you use `jquery`?
// jquery: true
},
files: ["src/**/*.[jt]s?(x)"],
},
// Tests and documentation
{
Expand All @@ -375,9 +385,6 @@ module.exports = {
"plugin:itgalaxy/browser",
"plugin:itgalaxy/react",
],
rules: {
"import/no-nodejs-modules": "off",
},
},
],
root: true,
Expand Down
11 changes: 11 additions & 0 deletions __tests__/fixtures/commonjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const subScript = require("./sub-module");

function outputSomething(line) {
return line;
}

outputSomething(subScript);
outputSomething(__filename);
outputSomething(__dirname);

module.exports = outputSomething;
9 changes: 1 addition & 8 deletions __tests__/fixtures/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const subScript = require("./sub-module");

function outputSomething(line) {
return line;
}

outputSomething(subScript);
outputSomething(__filename);
outputSomething(__dirname);

module.exports = outputSomething;
outputSomething("text");
Loading

0 comments on commit c5cf28c

Please sign in to comment.