Skip to content

Commit 75085e5

Browse files
Merge remote-tracking branch 'origin/master'
2 parents cebc426 + c5cf28c commit 75085e5

File tree

15 files changed

+302
-160
lines changed

15 files changed

+302
-160
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module.exports = {
44
extends: [
5-
"./lib/config/script.js",
5+
"./lib/config/commonjs.js",
66
"./lib/config/node.js",
77
"./lib/config/esnext.js",
88
"./lib/config/jsdoc-typescript.js",

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ rule (it is breaking changed by default).
77

88
## 134.0.0 - 2021-09-17
99

10-
- Changed: minimum required `eslint` version is `^7.32.0`
10+
- Added: `commonjs` preset (before it was the `script` preset).
11+
- Changed: `script` preset is now just `script`.
12+
- Changed: minimum required `eslint` version is `^7.32.0`.
1113
- Changed: minimum required `eslint-plugin-import` version is now `2.24.2`.
1214
- Changed: minimum required `eslint-plugin-markdown` version is now `2.2.1`.
1315
- Changed: minimum required `eslint-plugin-jest` version is now `24.4.2`.

README.md

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ module.exports = {
7373

7474
This plugin provides the following core configurations:
7575

76-
- [script](lib/config/script.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc).
76+
- [script](lib/config/script.js): preset for environment without `require`/`import` (old browsers or custom env).
77+
78+
Example of configuration:
79+
80+
```json
81+
{
82+
"extends": ["plugin:itgalaxy/script"]
83+
}
84+
```
85+
86+
- [commonjs](lib/config/commonjs.js): preset for [CommonJS modules](https://nodejs.org/docs/latest/api/modules.html) (`require`/`module.exports`/etc).
7787

7888
Example of configuration:
7989

@@ -129,7 +139,7 @@ console.log(import.meta.url);
129139
loadConfig("example");
130140
```
131141
132-
- [node](lib/config/node.js): use this for `Node.js` projects.
142+
- [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).
133143
134144
Preset contains environment and rules for `Node.js` code.
135145
@@ -138,9 +148,9 @@ Example of configuration:
138148
```js
139149
module.exports = {
140150
extends: [
141-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
142-
"plugin:itgalaxy/module",
143151
"plugin:itgalaxy/esnext",
152+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty"
153+
"plugin:itgalaxy/module",
144154
"plugin:itgalaxy/node",
145155
],
146156
};
@@ -155,9 +165,9 @@ Example of configuration:
155165
```js
156166
module.exports = {
157167
extends: [
158-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
159-
"plugin:itgalaxy/module",
160168
"plugin:itgalaxy/esnext",
169+
// You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
170+
"plugin:itgalaxy/module",
161171
"plugin:itgalaxy/browser",
162172
],
163173
};
@@ -174,9 +184,9 @@ Example of configuration:
174184
```js
175185
module.exports = {
176186
extends: [
177-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
178-
"plugin:itgalaxy/module",
179187
"plugin:itgalaxy/esnext",
188+
// You can use "plugin:itgalaxy/script" for old browsers or custom enviroment, "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
189+
"plugin:itgalaxy/module",
180190
],
181191
};
182192
```
@@ -188,10 +198,10 @@ Example of configuration:
188198
```js
189199
module.exports = {
190200
extends: [
191-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
201+
"plugin:itgalaxy/esnext",
202+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
192203
"plugin:itgalaxy/module",
193204
"plugin:itgalaxy/browser",
194-
"plugin:itgalaxy/esnext",
195205
"plugin:itgalaxy/react",
196206
],
197207
};
@@ -204,10 +214,10 @@ Example of configuration:
204214
```js
205215
module.exports = {
206216
extends: [
207-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
217+
"plugin:itgalaxy/esnext",
218+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
208219
"plugin:itgalaxy/module",
209220
"plugin:itgalaxy/browser",
210-
"plugin:itgalaxy/esnext",
211221
"plugin:itgalaxy/html",
212222
],
213223
};
@@ -223,11 +233,10 @@ Example of configuration:
223233
```js
224234
module.exports = {
225235
extends: [
226-
// You can use "plugin:itgalaxy/script" or "plugin:itgalaxy/dirty"
236+
"plugin:itgalaxy/esnext",
237+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
227238
"plugin:itgalaxy/module",
228-
// You can use "plugin:itgalaxy/node" or use them both
229239
"plugin:itgalaxy/browser",
230-
"plugin:itgalaxy/esnext",
231240
"plugin:itgalaxy/markdown",
232241
],
233242
};
@@ -240,10 +249,10 @@ Example of configuration:
240249
```js
241250
module.exports = {
242251
extends: [
252+
"plugin:itgalaxy/esnext",
253+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
243254
"plugin:itgalaxy/module",
244-
// You can use "plugin:itgalaxy/node" or use them both
245255
"plugin:itgalaxy/browser",
246-
"plugin:itgalaxy/esnext",
247256
"plugin:itgalaxy/ava",
248257
],
249258
};
@@ -258,10 +267,10 @@ Example of configuration:
258267
```js
259268
module.exports = {
260269
extends: [
270+
"plugin:itgalaxy/esnext",
271+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
261272
"plugin:itgalaxy/module",
262-
// You can use "plugin:itgalaxy/node" or use them both
263273
"plugin:itgalaxy/browser",
264-
"plugin:itgalaxy/esnext",
265274
"plugin:itgalaxy/jest",
266275
],
267276
};
@@ -274,9 +283,10 @@ Example of configuration:
274283
```js
275284
module.exports = {
276285
extends: [
286+
"plugin:itgalaxy/esnext",
287+
// You can use "plugin:itgalaxy/commonjs" or "plugin:itgalaxy/dirty" (useful for bundlers)
277288
"plugin:itgalaxy/module",
278289
"plugin:itgalaxy/node",
279-
"plugin:itgalaxy/esnext",
280290
"plugin:itgalaxy/jsdoc-typescript",
281291
],
282292
};
@@ -293,10 +303,10 @@ module.exports = {
293303

294304
module.exports = {
295305
extends: [
296-
"plugin:itgalaxy/script",
297-
// Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments
298-
"plugin:itgalaxy/node",
299306
"plugin:itgalaxy/esnext",
307+
"plugin:itgalaxy/commonjs",
308+
// Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler)
309+
"plugin:itgalaxy/node",
300310
"plugin:itgalaxy/jest",
301311
// Lint documentation
302312
"plugin:itgalaxy/markdown",
@@ -314,11 +324,11 @@ module.exports = {
314324
```js
315325
export default {
316326
extends: [
317-
// You can change this on "plugin:itgalaxy/dirty" if you use `node-babel` and have mixed code with `import` and `require`
327+
"plugin:itgalaxy/esnext",
328+
// You can change this on "plugin:itgalaxy/dirty" if you use `node-babel`, bundler and have mixed code with `import` and `require`
318329
"plugin:itgalaxy/module",
319-
// Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments
330+
// Use "plugin:itgalaxy/browser" if you write code for browser or use them both if you write for both environments (you need bundler)
320331
"plugin:itgalaxy/node",
321-
"plugin:itgalaxy/esnext",
322332
"plugin:itgalaxy/jest",
323333
// Lint documentation
324334
"plugin:itgalaxy/markdown",
@@ -339,9 +349,9 @@ module.exports = {
339349
// if you use ECMA modules everywhere (preferable)
340350
// Configuration files and scripts
341351
extends: [
342-
"plugin:itgalaxy/script",
343352
"plugin:itgalaxy/esnext",
344-
"plugin:itgalaxy/ava",
353+
"plugin:itgalaxy/commonjs",
354+
"plugin:itgalaxy/jest",
345355
// Lint documentation
346356
"plugin:itgalaxy/markdown",
347357
// Uncomment to use jsdoc typescript
@@ -350,6 +360,7 @@ module.exports = {
350360
overrides: [
351361
// Source code of application
352362
{
363+
files: ["src/**/*.[jt]s?(x)"],
353364
extends: [
354365
"plugin:itgalaxy/module",
355366
"plugin:itgalaxy/browser",
@@ -359,7 +370,6 @@ module.exports = {
359370
// Do you use `jquery`?
360371
// jquery: true
361372
},
362-
files: ["src/**/*.[jt]s?(x)"],
363373
},
364374
// Tests and documentation
365375
{
@@ -375,9 +385,6 @@ module.exports = {
375385
"plugin:itgalaxy/browser",
376386
"plugin:itgalaxy/react",
377387
],
378-
rules: {
379-
"import/no-nodejs-modules": "off",
380-
},
381388
},
382389
],
383390
root: true,

__tests__/fixtures/commonjs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const subScript = require("./sub-module");
2+
3+
function outputSomething(line) {
4+
return line;
5+
}
6+
7+
outputSomething(subScript);
8+
outputSomething(__filename);
9+
outputSomething(__dirname);
10+
11+
module.exports = outputSomething;

__tests__/fixtures/script.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
const subScript = require("./sub-module");
2-
31
function outputSomething(line) {
42
return line;
53
}
6-
7-
outputSomething(subScript);
8-
outputSomething(__filename);
9-
outputSomething(__dirname);
10-
11-
module.exports = outputSomething;
4+
outputSomething("text");

0 commit comments

Comments
 (0)