eslint-plugin-digigov 1.0.0 → 2.0.0-aefd0709

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.
@@ -1,26 +1,5 @@
1
1
  {
2
- "balanced-match@1.0.2": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
3
- "brace-expansion@2.0.1": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
4
- "find-up@3.0.0": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
5
- "fs.realpath@1.0.0": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
6
- "glob@8.1.0": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
7
- "ignore-walk@5.0.1": "sha512-yemi4pMf51WKT7khInJqAvsIGzoqYXblnsz0ql8tM+yi1EKYTY1evX4NAbJrLL/Aanr2HyZeluqU+Oi7MGHokw==",
8
- "inflight@1.0.6": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
9
- "inherits@2.0.4": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
10
- "locate-path@3.0.0": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
11
- "minimatch@5.1.6": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
12
- "mri@1.2.0": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==",
13
- "npm-bundled@2.0.1": "sha512-gZLxXdjEzE/+mOstGDqR6b0EkhJ+kM6fxM6vUuckuctuVPh80Q6pw/rSZj9s4Gex9GxWtIicO1pc8DB9KZWudw==",
14
- "npm-normalize-package-bin@2.0.0": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==",
15
- "npm-packlist@5.1.3": "sha512-263/0NGrn32YFYi4J533qzrQ/krmmrWwhKkzwTuM4f/07ug51odoaNjUexxO4vxlzURHcmYMH1QjvHjsNDKLVg==",
16
- "once@1.4.0": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
17
- "p-limit@2.3.0": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
18
- "p-locate@3.0.0": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
19
- "p-try@2.2.0": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
20
- "path-exists@3.0.0": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==",
21
- "picocolors@1.0.0": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==",
22
- "pkg-up@3.1.0": "sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==",
23
- "publint@0.1.8": "sha512-czOfocZAwS3d5RNrx4VyMxJJDyTn9MajMfuzJYlMrztFLrWkM+3KVdPozTfd8ka8aGWfR1cS66tMSDCgF70T+A==",
24
- "sade@1.8.1": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==",
25
- "wrappy@1.0.2": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
2
+ "../../plugins/eslint-plugin-digigov": "../../plugins/eslint-plugin-digigov:FuTkehhmJHluucbHj/hmgVsDXe1jqeerjTvx5/1AawY=:",
3
+ "/eslint@9.16.0(jiti@1.21.6)": "Missing shrinkwrap entry!",
4
+ "/publint@0.1.8": "Missing shrinkwrap entry!"
26
5
  }
package/index.js CHANGED
@@ -1,7 +1,21 @@
1
- exports.rules = {
2
- 'no-relative-imports': require('./rules/no-relative-imports'),
3
- };
1
+ import noRelativeImports from "./rules/no-relative-imports/index.js";
4
2
 
5
- exports.configs = {
6
- recommended: require('./config/recommended'),
3
+ const plugin = {
4
+ configs: {},
5
+ rules: {
6
+ "no-relative-imports": noRelativeImports,
7
+ },
7
8
  };
9
+
10
+ Object.assign(plugin.configs, {
11
+ recommended: {
12
+ plugins: {
13
+ digigov: plugin,
14
+ },
15
+ rules: {
16
+ "digigov/no-relative-imports": "warn",
17
+ },
18
+ },
19
+ });
20
+
21
+ export default plugin;
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "eslint-plugin-digigov",
3
- "version": "1.0.0",
3
+ "version": "2.0.0-aefd0709",
4
4
  "description": "Custom lint rules for digigov projects",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Devs <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "dependencies": {
9
- "pkg-up": "3.1.0",
10
- "publint": "0.1.8"
10
+ "@digigov/cli": "2.0.0-aefd0709"
11
11
  },
12
12
  "devDependencies": {
13
13
  "publint": "0.1.8"
14
14
  },
15
+ "peerDependencies": {
16
+ "eslint": "^9"
17
+ },
15
18
  "scripts": {
16
19
  "publint": "publint"
17
20
  }
18
- }
21
+ }
@@ -1,36 +1,33 @@
1
- const moduleVisitor = require('./moduleVisitor');
2
- const path = require('path');
3
- const pkgUp = require('pkg-up');
4
- const pkgLocation = pkgUp.sync()
5
- const package = require(pkgLocation)
6
- const project = {
7
- name: package.name,
8
- root: path.dirname(pkgLocation)
9
- }
1
+ import moduleVisitor from "./moduleVisitor.js";
2
+ import path from "path";
3
+ import { resolveProject } from "@digigov/cli/lib";
4
+
5
+ const project = resolveProject();
6
+
10
7
  const rule = {
11
8
  meta: {
12
- type: 'suggestion',
9
+ type: "suggestion",
13
10
  docs: {
14
- url: '',
11
+ description: "Disallow relative imports",
15
12
  },
16
- fixable: true,
13
+ fixable: "code",
17
14
  schema: [
18
15
  {
19
- type: 'object',
16
+ type: "object",
20
17
  properties: {
21
- commonjs: { type: 'boolean' },
22
- amd: { type: 'boolean' },
23
- esmodule: { type: 'boolean' },
18
+ commonjs: { type: "boolean" },
19
+ amd: { type: "boolean" },
20
+ esmodule: { type: "boolean" },
24
21
  ignore: {
25
- type: 'array',
22
+ type: "array",
26
23
  minItems: 1,
27
- items: { type: 'string' },
24
+ items: { type: "string" },
28
25
  uniqueItems: true,
29
26
  },
30
27
  root: {
31
- type: 'string',
32
- enum: ['package-name', 'src']
33
- }
28
+ type: "string",
29
+ enum: ["package-name", "src"],
30
+ },
34
31
  },
35
32
  additionalProperties: false,
36
33
  },
@@ -39,37 +36,34 @@ const rule = {
39
36
 
40
37
  create: function noRelativePackages(context) {
41
38
  const myPath = context.getFilename();
42
- let root = 'package-name'
43
- if(context.options.length){
44
- if(context.options[0].root){
45
- root = context.options[0].root
39
+ let root = "package-name";
40
+ if (context.options.length) {
41
+ if (context.options[0].root) {
42
+ root = context.options[0].root;
46
43
  }
47
44
  }
48
- if (myPath === '<text>') return {}; // can't check a non-file
45
+ if (myPath === "<text>") return {}; // can't check a non-file
49
46
 
50
47
  function checkSourceValue(sourceNode) {
51
48
  if (sourceNode.value.match(/^\./)) {
52
49
  const absoluteImportPath = path.resolve(
53
50
  path.dirname(myPath),
54
- sourceNode.value
51
+ sourceNode.value,
55
52
  );
56
- if(absoluteImportPath.endsWith('.svg')){
57
- return
53
+ if (absoluteImportPath.endsWith(".svg")) {
54
+ return;
58
55
  }
59
56
  // TODO: fix issue with importing svg files with babel-module-resolver
60
57
  // lint only import strings that dont have an svg extension
61
- if (path.extname(absoluteImportPath) !== '.svg') {
62
- const newPath = `'${root === 'package-name' ?project.name + '/':''}${absoluteImportPath
63
- .replace(
64
- `${project.root}/src/`,
65
- ''
66
- )
67
- .replace(/index$/, '')}'`;
58
+ if (path.extname(absoluteImportPath) !== ".svg") {
59
+ const newPath = `'${root === "package-name" ? project.name + "/" : ""}${absoluteImportPath
60
+ .replace(`${project.root}/src/`, "")
61
+ .replace(/index$/, "")}'`;
68
62
  context.report({
69
63
  node: sourceNode,
70
64
  message:
71
- 'Please use the absolute path of a file using the package name of your application as stated in the `name` key in your `package.json` file.\n' +
72
- 'Use of relative imports is not recommended\n' +
65
+ "Please use the absolute path of a file using the package name of your application as stated in the `name` key in your `package.json` file.\n" +
66
+ "Use of relative imports is not recommended\n" +
73
67
  `For this instance use ${newPath} instead of ${sourceNode.value}`,
74
68
  fix: (fixer) => {
75
69
  // see https://eslint.org/docs/developer-guide/working-with-rules#applying-fixes
@@ -84,4 +78,4 @@ const rule = {
84
78
  },
85
79
  };
86
80
 
87
- module.exports = rule;
81
+ export default rule;
@@ -7,7 +7,7 @@
7
7
  * @param {[type]} options [description]
8
8
  * @return {object}
9
9
  */
10
- module.exports = function visitModules(visitor, options) {
10
+ export default function visitModules(visitor, options) {
11
11
  // if esmodule is not explicitly disabled, it is assumed to be enabled
12
12
  options = Object.assign({ esmodule: true }, options);
13
13
 
@@ -33,12 +33,12 @@ module.exports = function visitModules(visitor, options) {
33
33
 
34
34
  // for esmodule dynamic `import()` calls
35
35
  function checkImportCall(node) {
36
- if (node.callee.type !== 'Import') return;
36
+ if (node.callee.type !== "Import") return;
37
37
  if (node.arguments.length !== 1) return;
38
38
 
39
39
  const modulePath = node.arguments[0];
40
- if (modulePath.type !== 'Literal') return;
41
- if (typeof modulePath.value !== 'string') return;
40
+ if (modulePath.type !== "Literal") return;
41
+ if (typeof modulePath.value !== "string") return;
42
42
 
43
43
  checkSourceValue(modulePath, node);
44
44
  }
@@ -46,30 +46,30 @@ module.exports = function visitModules(visitor, options) {
46
46
  // for CommonJS `require` calls
47
47
  // adapted from @mctep: http://git.io/v4rAu
48
48
  function checkCommon(call) {
49
- if (call.callee.type !== 'Identifier') return;
50
- if (call.callee.name !== 'require') return;
49
+ if (call.callee.type !== "Identifier") return;
50
+ if (call.callee.name !== "require") return;
51
51
  if (call.arguments.length !== 1) return;
52
52
 
53
53
  const modulePath = call.arguments[0];
54
- if (modulePath.type !== 'Literal') return;
55
- if (typeof modulePath.value !== 'string') return;
54
+ if (modulePath.type !== "Literal") return;
55
+ if (typeof modulePath.value !== "string") return;
56
56
 
57
57
  checkSourceValue(modulePath, call);
58
58
  }
59
59
 
60
60
  function checkAMD(call) {
61
- if (call.callee.type !== 'Identifier') return;
62
- if (call.callee.name !== 'require' && call.callee.name !== 'define') return;
61
+ if (call.callee.type !== "Identifier") return;
62
+ if (call.callee.name !== "require" && call.callee.name !== "define") return;
63
63
  if (call.arguments.length !== 2) return;
64
64
 
65
65
  const modules = call.arguments[0];
66
- if (modules.type !== 'ArrayExpression') return;
66
+ if (modules.type !== "ArrayExpression") return;
67
67
 
68
68
  for (const element of modules.elements) {
69
- if (element.type !== 'Literal') continue;
70
- if (typeof element.value !== 'string') continue;
69
+ if (element.type !== "Literal") continue;
70
+ if (typeof element.value !== "string") continue;
71
71
 
72
- if (element.value === 'require' || element.value === 'exports') continue; // magic modules: http://git.io/vByan
72
+ if (element.value === "require" || element.value === "exports") continue; // magic modules: http://git.io/vByan
73
73
 
74
74
  checkSourceValue(element, element);
75
75
  }
@@ -95,4 +95,4 @@ module.exports = function visitModules(visitor, options) {
95
95
  }
96
96
 
97
97
  return visitors;
98
- };
98
+ }
@@ -1,21 +0,0 @@
1
- /**
2
- * The basics.
3
- * @type {Object}
4
- */
5
- module.exports = {
6
- plugins: ['digigov'],
7
-
8
- rules: {
9
- // analysis/correctness
10
- // 'digigov/no-relative-imports': 'error',
11
- // red flags (thus, warnings)
12
- 'digigov/no-relative-imports': 'warn',
13
- },
14
-
15
- // need all these for parsing dependencies (even if _your_ code doesn't need
16
- // all of them)
17
- parserOptions: {
18
- sourceType: 'module',
19
- ecmaVersion: 2018,
20
- },
21
- };