@ornikar/eslint-plugin-ornikar 20.2.1 → 21.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +13 -0
- package/configs/all.js +1 -0
- package/docs/rules/forbid-fetch-import.md +21 -0
- package/package.json +5 -2
- package/rules/forbid-fetch-import.js +40 -0
- package/rules/forbid-fetch-import.test.js +35 -0
- package/rules/test-utils/RuleTester.js +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [21.0.0](https://github.com/ornikar/eslint-configs/compare/v20.2.1...v21.0.0) (2023-09-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* update to node 18 ECF-280 (#615)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* update to node 18 ECF-280 ([#615](https://github.com/ornikar/eslint-configs/issues/615)) ([51c7f5e](https://github.com/ornikar/eslint-configs/commit/51c7f5ee059a3517fba9ebec136e458d342c5c99))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [20.2.1](https://github.com/ornikar/eslint-configs/compare/v20.2.0...v20.2.1) (2023-09-20)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @ornikar/eslint-plugin-ornikar
|
package/configs/all.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Forbid importing libraries replacing fetch which is now available in native, browser and node.
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs).
|
|
4
|
+
|
|
5
|
+
## Fail
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import fetch from 'node-fetch';
|
|
9
|
+
|
|
10
|
+
fetch('/api').then(console.log);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Pass
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
fetch('/api').then(console.log);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
None
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ornikar/eslint-plugin-ornikar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "eslint plugin for ornikar",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "@ornikar/eslint-plugin-ornikar",
|
|
@@ -37,5 +37,8 @@
|
|
|
37
37
|
"@typescript-eslint/utils": "6.7.2",
|
|
38
38
|
"eslint": "8.49.0"
|
|
39
39
|
},
|
|
40
|
-
"
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.18.0"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "99c0a576f6ee3da108b9101453f6a0954c54b33e"
|
|
41
44
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.meta = {
|
|
4
|
+
type: 'problem',
|
|
5
|
+
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Forbid node-fetch import now that fetch is available in node and browsers',
|
|
8
|
+
category: 'Best Practices',
|
|
9
|
+
recommended: true,
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
messages: {
|
|
13
|
+
forbidden: 'import from "{{value}}" is forbidden. Fetch is available in browsers and node since 18.0.0.',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const fetchLibs = ['node-fetch', 'cross-fetch', 'isomorphic-fetch'];
|
|
18
|
+
|
|
19
|
+
exports.create = (context) => {
|
|
20
|
+
const checkNode = (node) => {
|
|
21
|
+
const importSource = node.source.value.trim();
|
|
22
|
+
|
|
23
|
+
if (fetchLibs.includes(importSource)) {
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: 'forbidden',
|
|
27
|
+
data: { value: importSource },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
ImportDeclaration: checkNode,
|
|
33
|
+
ExportNamedDeclaration(node) {
|
|
34
|
+
if (node.source) {
|
|
35
|
+
checkNode(node);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
ExportAllDeclaration: checkNode,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { RuleTester } = require('eslint');
|
|
4
|
+
const rule = require('./forbid-fetch-import');
|
|
5
|
+
|
|
6
|
+
const parserOptions = {
|
|
7
|
+
ecmaVersion: 2018,
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const ruleTester = new RuleTester({ parserOptions });
|
|
12
|
+
|
|
13
|
+
ruleTester.run('forbid-fetch-import', rule, {
|
|
14
|
+
valid: [
|
|
15
|
+
{
|
|
16
|
+
code: `
|
|
17
|
+
fetch('https://example.com');
|
|
18
|
+
`,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
invalid: [
|
|
22
|
+
{
|
|
23
|
+
code: `
|
|
24
|
+
import fetch from 'node-fetch';
|
|
25
|
+
fetch('https://example.com');
|
|
26
|
+
`,
|
|
27
|
+
errors: [
|
|
28
|
+
{
|
|
29
|
+
messageId: 'forbidden',
|
|
30
|
+
data: { value: 'node-fetch' },
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// eslint-disable-next-line import/no-unresolved -- waiting for node 18
|
|
4
3
|
const { after, describe, it } = require('node:test');
|
|
5
|
-
// eslint-disable-next-line import/no-unresolved
|
|
4
|
+
// eslint-disable-next-line import/no-unresolved -- missing main field
|
|
6
5
|
const { RuleTester } = require('@typescript-eslint/rule-tester');
|
|
7
6
|
|
|
8
7
|
RuleTester.afterAll = after;
|