@checkdigit/eslint-plugin 4.0.0 → 4.1.0-PR.32-b8ce
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/LICENSE.txt +1 -1
- package/README.md +6 -8
- package/SECURITY.md +14 -0
- package/dist/file-path-comment.d.ts +1 -0
- package/dist/file-path-comment.d.ts.map +1 -0
- package/dist/file-path-comment.js +86 -0
- package/dist/file-path-comment.js.map +1 -0
- package/dist/file-path-comment.spec.d.ts +2 -0
- package/dist/file-path-comment.spec.d.ts.map +1 -0
- package/dist/file-path-comment.spec.js +72 -0
- package/dist/file-path-comment.spec.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/dist/no-card-numbers.d.ts +1 -0
- package/dist/no-card-numbers.d.ts.map +1 -0
- package/dist/no-card-numbers.js +138 -0
- package/dist/no-card-numbers.js.map +1 -0
- package/dist/no-card-numbers.spec.d.ts +2 -0
- package/dist/no-card-numbers.spec.d.ts.map +1 -0
- package/dist/no-card-numbers.spec.js +134 -0
- package/dist/no-card-numbers.spec.js.map +1 -0
- package/dist/no-uuid.d.ts +4 -0
- package/dist/no-uuid.d.ts.map +1 -0
- package/dist/no-uuid.js +102 -0
- package/dist/no-uuid.js.map +1 -0
- package/dist/no-uuid.spec.d.ts +2 -0
- package/dist/no-uuid.spec.d.ts.map +1 -0
- package/dist/no-uuid.spec.js +78 -0
- package/dist/no-uuid.spec.js.map +1 -0
- package/package.json +1 -71
- package/src/file-path-comment.ts +88 -0
- package/src/index.ts +35 -0
- package/src/no-card-numbers.ts +151 -0
- package/src/no-uuid.ts +109 -0
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
# checkdigit/eslint-plugin
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[](https://status.david-dm.org/gh/checkdigit/eslint-plugin.svg)
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2021-2022 [Check Digit, LLC](https://checkdigit.com)
|
|
3
|
+
Copyright (c) 2021-2023 [Check Digit, LLC](https://checkdigit.com)
|
|
7
4
|
|
|
8
5
|
## Rules
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
- `@checkdigit/no-card-numbers`
|
|
8
|
+
- `@checkdigit/file-path-comment`
|
|
9
|
+
- `@checkdigit/no-uuid`
|
|
12
10
|
|
|
13
11
|
## Configurations
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
- `@checkdigit/all`
|
|
14
|
+
- `@checkdigit/recommended`
|
|
17
15
|
|
|
18
16
|
## License
|
|
19
17
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
These versions of `@checkdigit/eslint-plugin` are currently being supported with security updates.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | ------------------ |
|
|
9
|
+
| \>= 4.0 | :white_check_mark: |
|
|
10
|
+
| \< 4.0 | :x: |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
Please create an issue at https://github.com/checkdigit/eslint-plugin/issues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-path-comment.d.ts","sourceRoot":"","sources":["../src/file-path-comment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;;AAQnC,wBA6EqB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file-path-comment.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2021-2022 Check Digit, LLC
|
|
6
|
+
*
|
|
7
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
8
|
+
*/
|
|
9
|
+
exports.default = {
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'suggestion',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Validate that first line of file is a path to the file',
|
|
14
|
+
url: 'https://github.com/checkdigit/eslint-plugin',
|
|
15
|
+
},
|
|
16
|
+
fixable: 'code',
|
|
17
|
+
},
|
|
18
|
+
create(context) {
|
|
19
|
+
const firstLine = context.getSourceCode().getLines()[0];
|
|
20
|
+
const expectedPath = context.getFilename().split('src/')[1];
|
|
21
|
+
if (expectedPath === undefined) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
if (!firstLine.startsWith('//')) {
|
|
25
|
+
if (firstLine.startsWith('/*')) {
|
|
26
|
+
context.report({
|
|
27
|
+
loc: {
|
|
28
|
+
start: {
|
|
29
|
+
line: 0,
|
|
30
|
+
column: 0,
|
|
31
|
+
},
|
|
32
|
+
end: {
|
|
33
|
+
line: 0,
|
|
34
|
+
column: 1,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
message: 'first line cannot be a block comment',
|
|
38
|
+
fix(fixer) {
|
|
39
|
+
return fixer.insertTextBeforeRange([0, 0], `// ${expectedPath}\n\n`);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
context.report({
|
|
45
|
+
loc: {
|
|
46
|
+
start: {
|
|
47
|
+
line: 0,
|
|
48
|
+
column: 0,
|
|
49
|
+
},
|
|
50
|
+
end: {
|
|
51
|
+
line: 0,
|
|
52
|
+
column: 1,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
message: 'first line is not a comment with the file path',
|
|
56
|
+
fix(fixer) {
|
|
57
|
+
return fixer.insertTextBeforeRange([0, 0], `// ${expectedPath}\n\n`);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const actualComment = firstLine.split('// ')[1];
|
|
64
|
+
if (expectedPath !== actualComment) {
|
|
65
|
+
context.report({
|
|
66
|
+
loc: {
|
|
67
|
+
start: {
|
|
68
|
+
line: 0,
|
|
69
|
+
column: 0,
|
|
70
|
+
},
|
|
71
|
+
end: {
|
|
72
|
+
line: 0,
|
|
73
|
+
column: 1,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
message: 'first line is a comment but is not a path to the file',
|
|
77
|
+
fix(fixer) {
|
|
78
|
+
return fixer.replaceTextRange([0, firstLine.length], `// ${expectedPath}`);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=file-path-comment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-path-comment.js","sourceRoot":"","sources":["../src/file-path-comment.ts"],"names":[],"mappings":";AAAA,uBAAuB;;AAIvB;;;;GAIG;AAEH,kBAAe;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,wDAAwD;YACrE,GAAG,EAAE,6CAA6C;SACnD;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAW,CAAC;QAClE,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5D,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,OAAO,EAAE,CAAC;SACX;QAED,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC/B,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAC9B,OAAO,CAAC,MAAM,CAAC;oBACb,GAAG,EA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AY,EAAE,CAAC,CAAC;oBAC7E,CAAC;iBACF,CAAC,CAAC;aACJ;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACiB,CAAC","sourcesContent":["// file-path-comment.ts\n\nimport type { Rule } from 'eslint';\n\n/*\n * Copyright (c) 2021-2022 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nexport default {\n meta: {\n type: 'suggestion',\n docs: {\n description: 'Validate that first line of file is a path to the file',\n url: 'https://github.com/checkdigit/eslint-plugin',\n },\n fixable: 'code',\n },\n create(context) {\n const firstLine = context.getSourceCode().getLines()[0] as string;\n const expectedPath = context.getFilename().split('src/')[1];\n\n if (expectedPath === undefined) {\n return {};\n }\n\n if (!firstLine.startsWith('//')) {\n if (firstLine.startsWith('/*')) {\n context.report({\n loc: {\n start: {\n line: 0,\n column: 0,\n },\n end: {\n line: 0,\n column: 1,\n },\n },\n message: 'first line cannot be a block comment',\n fix(fixer: Rule.RuleFixer) {\n return fixer.insertTextBeforeRange([0, 0], `// ${expectedPath}\\n\\n`);\n },\n });\n } else {\n context.report({\n loc: {\n start: {\n line: 0,\n column: 0,\n },\n end: {\n line: 0,\n column: 1,\n },\n },\n message: 'first line is not a comment with the file path',\n fix(fixer: Rule.RuleFixer) {\n return fixer.insertTextBeforeRange([0, 0], `// ${expectedPath}\\n\\n`);\n },\n });\n }\n } else {\n const actualComment = firstLine.split('// ')[1];\n if (expectedPath !== actualComment) {\n context.report({\n loc: {\n start: {\n line: 0,\n column: 0,\n },\n end: {\n line: 0,\n column: 1,\n },\n },\n message: 'first line is a comment but is not a path to the file',\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceTextRange([0, firstLine.length], `// ${expectedPath}`);\n },\n });\n }\n }\n\n return {};\n },\n} as Rule.RuleModule;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-path-comment.spec.d.ts","sourceRoot":"","sources":["../src/file-path-comment.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file-path-comment.spec.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2021-2022 Check Digit, LLC
|
|
9
|
+
*
|
|
10
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
11
|
+
*/
|
|
12
|
+
const eslint_1 = require("eslint");
|
|
13
|
+
const file_path_comment_1 = __importDefault(require("./file-path-comment"));
|
|
14
|
+
describe('file-path-comment', () => {
|
|
15
|
+
const ruleTester = new eslint_1.RuleTester({ parserOptions: { ecmaVersion: 2020 } });
|
|
16
|
+
ruleTester.run('file-path-comment', file_path_comment_1.default, {
|
|
17
|
+
valid: [
|
|
18
|
+
{
|
|
19
|
+
filename: 'src/world/hello.ts',
|
|
20
|
+
code: `// world/hello.ts`,
|
|
21
|
+
parserOptions: {
|
|
22
|
+
project: './tsconfig.json',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
filename: 'src/hello.ts',
|
|
27
|
+
code: `// hello.ts\n`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
filename: 'hello.ts',
|
|
31
|
+
code: `// whatever does not matter\n`,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
filename: 'source/hello.ts',
|
|
35
|
+
code: `// whatever does not matter\n`,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
invalid: [
|
|
39
|
+
{
|
|
40
|
+
filename: 'src/hello.ts',
|
|
41
|
+
code: `// not-hello.ts`,
|
|
42
|
+
errors: [{ message: 'first line is a comment but is not a path to the file' }],
|
|
43
|
+
output: `// hello.ts`,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
filename: 'src/hello.ts',
|
|
47
|
+
code: `//hello.ts\n`,
|
|
48
|
+
errors: [{ message: 'first line is a comment but is not a path to the file' }],
|
|
49
|
+
output: `// hello.ts\n`,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
filename: 'src/hello.ts',
|
|
53
|
+
code: `/* not-hello.ts */`,
|
|
54
|
+
errors: [{ message: 'first line cannot be a block comment' }],
|
|
55
|
+
output: `// hello.ts\n\n/* not-hello.ts */`,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
filename: 'src/hello.ts',
|
|
59
|
+
code: `const x = 123;`,
|
|
60
|
+
errors: [{ message: 'first line is not a comment with the file path' }],
|
|
61
|
+
output: `// hello.ts\n\nconst x = 123;`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
filename: 'src/hello.ts',
|
|
65
|
+
code: ``,
|
|
66
|
+
errors: [{ message: 'first line is not a comment with the file path' }],
|
|
67
|
+
output: `// hello.ts\n\n`,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=file-path-comment.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-path-comment.spec.js","sourceRoot":"","sources":["../src/file-path-comment.spec.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;;;AAE5B;;;;GAIG;AAEH,mCAAoC;AAEpC,4EAAuC;AAEvC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,MAAM,UAAU,GAAG,IAAI,mBAAU,CAAC,EAAE,aAAa,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAE5E,UAAU,CAAC,GAAG,CAAC,mBAAmB,EAAE,2BAAI,EAAE;QACxC,KAAK,EAAE;YACL;gBACE,QAAQ,EAAE,oBAAoB;gBAC9B,IAAI,EAAE,mBAAmB;gBACzB,aAAa,EAAE;oBACb,OAAO,EAAE,iBAAiB;iBAC3B;aACF;YACD;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,eAAe;aACtB;YACD;gBACE,QAAQ,EAAE,UAAU;gBACpB,IAAI,EAAE,+BAA+B;aACtC;YACD;gBACE,QAAQ,EAAE,iBAAiB;gBAC3B,IAAI,EAAE,+BAA+B;aACtC;SACF;QACD,OAAO,EAAE;YACP;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,iBAAiB;gBACvB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,uDAAuD,EAAE,CAAC;gBAC9E,MAAM,EAAE,aAAa;aACtB;YACD;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,cAAc;gBACpB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,uDAAuD,EAAE,CAAC;gBAC9E,MAAM,EAAE,eAAe;aACxB;YACD;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,oBAAoB;gBAC1B,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,sCAAsC,EAAE,CAAC;gBAC7D,MAAM,EAAE,mCAAmC;aAC5C;YACD;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,gBAAgB;gBACtB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,gDAAgD,EAAE,CAAC;gBACvE,MAAM,EAAE,+BAA+B;aACxC;YACD;gBACE,QAAQ,EAAE,cAAc;gBACxB,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,gDAAgD,EAAE,CAAC;gBACvE,MAAM,EAAE,iBAAiB;aAC1B;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// file-path-comment.spec.ts\n\n/*\n * Copyright (c) 2021-2022 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport { RuleTester } from 'eslint';\n\nimport rule from './file-path-comment';\n\ndescribe('file-path-comment', () => {\n const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } });\n\n ruleTester.run('file-path-comment', rule, {\n valid: [\n {\n filename: 'src/world/hello.ts',\n code: `// world/hello.ts`,\n parserOptions: {\n project: './tsconfig.json',\n },\n },\n {\n filename: 'src/hello.ts',\n code: `// hello.ts\\n`,\n },\n {\n filename: 'hello.ts',\n code: `// whatever does not matter\\n`,\n },\n {\n filename: 'source/hello.ts',\n code: `// whatever does not matter\\n`,\n },\n ],\n invalid: [\n {\n filename: 'src/hello.ts',\n code: `// not-hello.ts`,\n errors: [{ message: 'first line is a comment but is not a path to the file' }],\n output: `// hello.ts`,\n },\n {\n filename: 'src/hello.ts',\n code: `//hello.ts\\n`,\n errors: [{ message: 'first line is a comment but is not a path to the file' }],\n output: `// hello.ts\\n`,\n },\n {\n filename: 'src/hello.ts',\n code: `/* not-hello.ts */`,\n errors: [{ message: 'first line cannot be a block comment' }],\n output: `// hello.ts\\n\\n/* not-hello.ts */`,\n },\n {\n filename: 'src/hello.ts',\n code: `const x = 123;`,\n errors: [{ message: 'first line is not a comment with the file path' }],\n output: `// hello.ts\\n\\nconst x = 123;`,\n },\n {\n filename: 'src/hello.ts',\n code: ``,\n errors: [{ message: 'first line is not a comment with the file path' }],\n output: `// hello.ts\\n\\n`,\n },\n ],\n });\n});\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,20 +2,24 @@ declare const _default: {
|
|
|
2
2
|
rules: {
|
|
3
3
|
'file-path-comment': import("eslint").Rule.RuleModule;
|
|
4
4
|
'no-card-numbers': import("eslint").Rule.RuleModule;
|
|
5
|
+
'no-uuid': import("eslint").Rule.RuleModule;
|
|
5
6
|
};
|
|
6
7
|
configs: {
|
|
7
8
|
all: {
|
|
8
9
|
rules: {
|
|
9
10
|
'@checkdigit/no-card-numbers': string;
|
|
10
11
|
'@checkdigit/file-path-comment': string;
|
|
12
|
+
'@checkdigit/no-uuid': string;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
recommended: {
|
|
14
16
|
rules: {
|
|
15
17
|
'@checkdigit/no-card-numbers': string;
|
|
16
18
|
'@checkdigit/file-path-comment': string;
|
|
19
|
+
'@checkdigit/no-uuid': string;
|
|
17
20
|
};
|
|
18
21
|
};
|
|
19
22
|
};
|
|
20
23
|
};
|
|
21
24
|
export default _default;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAYA,wBAsBE"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// index.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2021-2022 Check Digit, LLC
|
|
9
|
+
*
|
|
10
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
11
|
+
*/
|
|
12
|
+
const file_path_comment_1 = __importDefault(require("./file-path-comment"));
|
|
13
|
+
const no_card_numbers_1 = __importDefault(require("./no-card-numbers"));
|
|
14
|
+
const no_uuid_1 = __importDefault(require("./no-uuid"));
|
|
15
|
+
exports.default = {
|
|
16
|
+
rules: {
|
|
17
|
+
'file-path-comment': file_path_comment_1.default,
|
|
18
|
+
'no-card-numbers': no_card_numbers_1.default,
|
|
19
|
+
'no-uuid': no_uuid_1.default,
|
|
20
|
+
},
|
|
21
|
+
configs: {
|
|
22
|
+
all: {
|
|
23
|
+
rules: {
|
|
24
|
+
'@checkdigit/no-card-numbers': 'error',
|
|
25
|
+
'@checkdigit/file-path-comment': 'error',
|
|
26
|
+
'@checkdigit/no-uuid': 'error',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
recommended: {
|
|
30
|
+
rules: {
|
|
31
|
+
'@checkdigit/no-card-numbers': 'error',
|
|
32
|
+
'@checkdigit/file-path-comment': 'off',
|
|
33
|
+
'@checkdigit/no-uuid': 'error',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,WAAW;;;;;AAEX;;;;GAIG;AAEH,4EAAkD;AAClD,wEAA8C;AAC9C,wDAA+B;AAE/B,kBAAe;IACb,KAAK,EAAE;QACL,mBAAmB,EAAE,2BAAe;QACpC,iBAAiB,EAAE,yBAAa;QAChC,SAAS,EAAE,iBAAM;KAClB;IACD,OAAO,EAAE;QACP,GAAG,EAAE;YACH,KAAK,EAAE;gBACL,6BAA6B,EAAE,OAAO;gBACtC,+BAA+B,EAAE,OAAO;gBACxC,qBAAqB,EAAE,OAAO;aAC/B;SACF;QACD,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,6BAA6B,EAAE,OAAO;gBACtC,+BAA+B,EAAE,KAAK;gBACtC,qBAAqB,EAAE,OAAO;aAC/B;SACF;KACF;CACF,CAAC","sourcesContent":["// index.ts\n\n/*\n * Copyright (c) 2021-2022 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport filePathComment from './file-path-comment';\nimport noCardNumbers from './no-card-numbers';\nimport noUuid from './no-uuid';\n\nexport default {\n rules: {\n 'file-path-comment': filePathComment,\n 'no-card-numbers': noCardNumbers,\n 'no-uuid': noUuid,\n },\n configs: {\n all: {\n rules: {\n '@checkdigit/no-card-numbers': 'error',\n '@checkdigit/file-path-comment': 'error',\n '@checkdigit/no-uuid': 'error',\n },\n },\n recommended: {\n rules: {\n '@checkdigit/no-card-numbers': 'error',\n '@checkdigit/file-path-comment': 'off',\n '@checkdigit/no-uuid': 'error',\n },\n },\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-card-numbers.d.ts","sourceRoot":"","sources":["../src/no-card-numbers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;;AAkGnC,wBA2CqB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// no-card-numbers.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const CARD_NUMBER_FOUND = 'CARD_NUMBER_FOUND';
|
|
5
|
+
const CARD_NUMBERS_FOUND = 'CARD_NUMBERS_FOUND';
|
|
6
|
+
const cardNumberRegex = /\d{15,19}/gmu;
|
|
7
|
+
const allowCardNumbers = [
|
|
8
|
+
'4111111111111111',
|
|
9
|
+
'111111111111111',
|
|
10
|
+
'000000000000000',
|
|
11
|
+
'0000000000000000',
|
|
12
|
+
'00000000000000000',
|
|
13
|
+
'000000000000000000',
|
|
14
|
+
'0000000000000000000',
|
|
15
|
+
];
|
|
16
|
+
function luhnCheck(cardNumber) {
|
|
17
|
+
return (cardNumber
|
|
18
|
+
.split('')
|
|
19
|
+
.reverse()
|
|
20
|
+
.map((digit) => parseInt(digit, 10))
|
|
21
|
+
.reduce((previousValue, currentValue, index) => {
|
|
22
|
+
let value = currentValue;
|
|
23
|
+
if (index % 2 === 1) {
|
|
24
|
+
value *= 2;
|
|
25
|
+
// eslint-disable-next-line no-magic-numbers
|
|
26
|
+
if (value > 9) {
|
|
27
|
+
value = (value % 10) + 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return previousValue + value;
|
|
31
|
+
}, 0) %
|
|
32
|
+
10 ===
|
|
33
|
+
0);
|
|
34
|
+
}
|
|
35
|
+
function checkForCardNumbers(value, context, node, loc) {
|
|
36
|
+
const matches = value.match(cardNumberRegex);
|
|
37
|
+
if (matches === null) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const cardNumbers = matches.filter((match) => luhnCheck(match) &&
|
|
41
|
+
allowCardNumbers.indexOf(match) === -1 &&
|
|
42
|
+
// any 16-digit number that begins with 0-1 or 7-9 is not a valid card number
|
|
43
|
+
match[0] !== '0' &&
|
|
44
|
+
match[0] !== '1' &&
|
|
45
|
+
match[0] !== '7' &&
|
|
46
|
+
match[0] !== '8' &&
|
|
47
|
+
match[0] !== '9');
|
|
48
|
+
if (cardNumbers.length === 1) {
|
|
49
|
+
if (node !== undefined) {
|
|
50
|
+
context.report({
|
|
51
|
+
messageId: CARD_NUMBER_FOUND,
|
|
52
|
+
data: {
|
|
53
|
+
number: cardNumbers[0],
|
|
54
|
+
},
|
|
55
|
+
node,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (loc !== undefined) {
|
|
59
|
+
context.report({
|
|
60
|
+
messageId: CARD_NUMBER_FOUND,
|
|
61
|
+
data: {
|
|
62
|
+
number: cardNumbers[0],
|
|
63
|
+
},
|
|
64
|
+
loc: {
|
|
65
|
+
start: loc.start,
|
|
66
|
+
end: loc.end,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (cardNumbers.length > 1) {
|
|
72
|
+
if (node !== undefined) {
|
|
73
|
+
context.report({
|
|
74
|
+
messageId: CARD_NUMBERS_FOUND,
|
|
75
|
+
data: {
|
|
76
|
+
numbers: matches.join(', '),
|
|
77
|
+
},
|
|
78
|
+
node,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else if (loc !== undefined) {
|
|
82
|
+
context.report({
|
|
83
|
+
messageId: CARD_NUMBERS_FOUND,
|
|
84
|
+
data: {
|
|
85
|
+
numbers: matches.join(', '),
|
|
86
|
+
},
|
|
87
|
+
loc: {
|
|
88
|
+
start: loc.start,
|
|
89
|
+
end: loc.end,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.default = {
|
|
96
|
+
meta: {
|
|
97
|
+
type: 'problem',
|
|
98
|
+
docs: {
|
|
99
|
+
description: 'Detects if a luhn passing card number',
|
|
100
|
+
url: 'https://github.com/checkdigit/eslint-plugin',
|
|
101
|
+
},
|
|
102
|
+
messages: {
|
|
103
|
+
[CARD_NUMBER_FOUND]: `Valid card number: "{{ number }}"`,
|
|
104
|
+
[CARD_NUMBERS_FOUND]: `Multiple valid card numbers found: "{{ numbers }}"`,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
create(context) {
|
|
108
|
+
const sourceCode = context.getSourceCode();
|
|
109
|
+
const comments = sourceCode.getAllComments();
|
|
110
|
+
comments.forEach((comment) => {
|
|
111
|
+
if (comment.loc !== undefined && comment.loc !== null) {
|
|
112
|
+
checkForCardNumbers(comment.value, context, undefined, comment.loc);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
Literal(node) {
|
|
117
|
+
if (node.value === undefined) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (typeof node.value !== 'string' && typeof node.value !== 'number') {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const value = `${node.value}`;
|
|
124
|
+
checkForCardNumbers(value, context, node);
|
|
125
|
+
},
|
|
126
|
+
TemplateElement(node) {
|
|
127
|
+
if (!node.value) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (typeof node.value.cooked !== 'string') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
checkForCardNumbers(node.value.cooked, context, node);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=no-card-numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-card-numbers.js","sourceRoot":"","sources":["../src/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;iBACR;gBACD,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE;oBACzC,OAAO;iBACR;gBACD,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;SACF,CAAC;IACJ,CAAC;CACiB,CAAC","sourcesContent":["// no-card-numbers.ts\n\n/*\n * Copyright (c) 2021-2022 Check Digit, LLC\n *\n * This code is licensed under the MIT license (see LICENSE.txt for details).\n */\n\nimport type { Node, SourceLocation } from 'estree';\nimport type { Rule } from 'eslint';\n\nconst CARD_NUMBER_FOUND = 'CARD_NUMBER_FOUND';\nconst CARD_NUMBERS_FOUND = 'CARD_NUMBERS_FOUND';\nconst cardNumberRegex = /\\d{15,19}/gmu;\nconst allowCardNumbers = [\n '4111111111111111',\n '111111111111111',\n '000000000000000',\n '0000000000000000',\n '00000000000000000',\n '000000000000000000',\n '0000000000000000000',\n];\n\nfunction luhnCheck(cardNumber: string) {\n return (\n cardNumber\n .split('')\n .reverse()\n .map((digit) => parseInt(digit, 10))\n .reduce((previousValue, currentValue, index) => {\n let value = currentValue;\n if (index % 2 === 1) {\n value *= 2;\n // eslint-disable-next-line no-magic-numbers\n if (value > 9) {\n value = (value % 10) + 1;\n }\n }\n return previousValue + value;\n }, 0) %\n 10 ===\n 0\n );\n}\n\nfunction checkForCardNumbers(value: string, context: Rule.RuleContext, node?: Node, loc?: SourceLocation) {\n const matches = value.match(cardNumberRegex);\n if (matches === null) {\n return;\n }\n const cardNumbers = matches.filter(\n (match) =>\n luhnCheck(match) &&\n allowCardNumbers.indexOf(match) === -1 &&\n // any 16-digit number that begins with 0-1 or 7-9 is not a valid card number\n match[0] !== '0' &&\n match[0] !== '1' &&\n match[0] !== '7' &&\n match[0] !== '8' &&\n match[0] !== '9'\n );\n if (cardNumbers.length === 1) {\n if (node !== undefined) {\n context.report({\n messageId: CARD_NUMBER_FOUND,\n data: {\n number: cardNumbers[0] as string,\n },\n node,\n });\n } else if (loc !== undefined) {\n context.report({\n messageId: CARD_NUMBER_FOUND,\n data: {\n number: cardNumbers[0] as string,\n },\n loc: {\n start: loc.start,\n end: loc.end,\n },\n });\n }\n } else if (cardNumbers.length > 1) {\n if (node !== undefined) {\n context.report({\n messageId: CARD_NUMBERS_FOUND,\n data: {\n numbers: matches.join(', '),\n },\n node,\n });\n } else if (loc !== undefined) {\n context.report({\n messageId: CARD_NUMBERS_FOUND,\n data: {\n numbers: matches.join(', '),\n },\n loc: {\n start: loc.start,\n end: loc.end,\n },\n });\n }\n }\n}\n\nexport default {\n meta: {\n type: 'problem',\n docs: {\n description: 'Detects if a luhn passing card number',\n url: 'https://github.com/checkdigit/eslint-plugin',\n },\n messages: {\n [CARD_NUMBER_FOUND]: `Valid card number: \"{{ number }}\"`,\n [CARD_NUMBERS_FOUND]: `Multiple valid card numbers found: \"{{ numbers }}\"`,\n },\n },\n create(context) {\n const sourceCode = context.getSourceCode();\n const comments = sourceCode.getAllComments();\n\n comments.forEach((comment) => {\n if (comment.loc !== undefined && comment.loc !== null) {\n checkForCardNumbers(comment.value, context, undefined, comment.loc);\n }\n });\n return {\n Literal(node) {\n if (node.value === undefined) {\n return;\n }\n if (typeof node.value !== 'string' && typeof node.value !== 'number') {\n return;\n }\n const value = `${node.value}`;\n checkForCardNumbers(value, context, node);\n },\n TemplateElement(node) {\n if (!node.value) {\n return;\n }\n if (typeof node.value.cooked !== 'string') {\n return;\n }\n checkForCardNumbers(node.value.cooked, context, node);\n },\n };\n },\n} as Rule.RuleModule;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-card-numbers.spec.d.ts","sourceRoot":"","sources":["../src/no-card-numbers.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// no-card-numbers.spec.ts
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2021-2022 Check Digit, LLC
|
|
9
|
+
*
|
|
10
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
11
|
+
*/
|
|
12
|
+
const eslint_1 = require("eslint");
|
|
13
|
+
const no_card_numbers_1 = __importDefault(require("./no-card-numbers"));
|
|
14
|
+
const CARD_NUMBER_FOUND = 'CARD_NUMBER_FOUND';
|
|
15
|
+
const CARD_NUMBERS_FOUND = 'CARD_NUMBERS_FOUND';
|
|
16
|
+
const CARD_NUMBER_FOUND_MSG = {
|
|
17
|
+
messageId: CARD_NUMBER_FOUND,
|
|
18
|
+
};
|
|
19
|
+
const CARD_NUMBERS_FOUND_MSG = {
|
|
20
|
+
messageId: CARD_NUMBERS_FOUND,
|
|
21
|
+
};
|
|
22
|
+
const STRING_TEST = `
|
|
23
|
+
const NOT_A_SECRET = "I'm not a secret, I think";
|
|
24
|
+
`;
|
|
25
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
26
|
+
const TEMPLATE_TEST = "const NOT_A_SECRET = `A template that isn't a secret. ${1+1} = 2`";
|
|
27
|
+
const CONTAINS_CARD_NUMBER_IN_NUMBER = `
|
|
28
|
+
const foo = 4507894813950280;
|
|
29
|
+
`;
|
|
30
|
+
const CONTAINS_A_PASSING_CARD_NUMBER = `
|
|
31
|
+
const foo = 4111111111111111;
|
|
32
|
+
const fuz = 123111111111111111567;
|
|
33
|
+
const bar = 111111111111111;
|
|
34
|
+
const baz = 000000000000000;
|
|
35
|
+
const far = 0000000000000000;
|
|
36
|
+
const faz = 00000000000000000;
|
|
37
|
+
const doo = 000000000000000000;
|
|
38
|
+
const dar = 0000000000000000000;
|
|
39
|
+
`;
|
|
40
|
+
const CONTAINS_A_PASSING_CARD_NUMBER_IN_COMMENT = `
|
|
41
|
+
// 4111111111111111;
|
|
42
|
+
// 123111111111111111567;
|
|
43
|
+
// 111111111111111;
|
|
44
|
+
// 000000000000000;
|
|
45
|
+
// 0000000000000000;
|
|
46
|
+
// 00000000000000000;
|
|
47
|
+
// 000000000000000000;
|
|
48
|
+
// 0000000000000000000;
|
|
49
|
+
`;
|
|
50
|
+
const CONTAINS_SEVERAL_CARD_NUMBERS_IN_STRING = `
|
|
51
|
+
const foo = '4507894813950280 aa 4939816588221579';
|
|
52
|
+
`;
|
|
53
|
+
const CONTAINS_CARD_NUMBER_IN_COMMENT = `
|
|
54
|
+
// this test will be using this valid card number -> 4507894813950280
|
|
55
|
+
const foo = 'nothing wrong here';
|
|
56
|
+
`;
|
|
57
|
+
const CONTAINS_SEVERAL_CARD_NUMBERS_IN_COMMENT = `
|
|
58
|
+
// this test will be using these valid card numbers -> 4507894813950280 and 4732643354095204
|
|
59
|
+
const foo = 'nothing wrong here';
|
|
60
|
+
`;
|
|
61
|
+
const STRING_WITH_CARD_NUMBER_THAT_DOESNT_PASS_LUHN_CHECK = `
|
|
62
|
+
const foo = 4507894813950285;
|
|
63
|
+
`;
|
|
64
|
+
const CONTAINS_PASSING_BUT_INVALID_0_PREFIX_CARD_NUMBER_IN_STRING = `
|
|
65
|
+
const foo = '0027576507977237';
|
|
66
|
+
`;
|
|
67
|
+
const CONTAINS_PASSING_BUT_INVALID_1_PREFIX_CARD_NUMBER_IN_STRING = `
|
|
68
|
+
const foo = '1237027241007794';
|
|
69
|
+
`;
|
|
70
|
+
const CONTAINS_PASSING_BUT_INVALID_7_PREFIX_CARD_NUMBER_IN_STRING = `
|
|
71
|
+
const foo = '7603721237334401';
|
|
72
|
+
`;
|
|
73
|
+
const CONTAINS_PASSING_BUT_INVALID_8_PREFIX_CARD_NUMBER_IN_STRING = `
|
|
74
|
+
const foo = '8119915764450821';
|
|
75
|
+
`;
|
|
76
|
+
const CONTAINS_PASSING_BUT_INVALID_9_PREFIX_CARD_NUMBER_IN_STRING = `
|
|
77
|
+
const foo = '9118724531442999';
|
|
78
|
+
`;
|
|
79
|
+
describe('no-card-numbers', () => {
|
|
80
|
+
const ruleTester = new eslint_1.RuleTester({ parserOptions: { ecmaVersion: 2020 } });
|
|
81
|
+
ruleTester.run('no-card-numbers', no_card_numbers_1.default, {
|
|
82
|
+
valid: [
|
|
83
|
+
{
|
|
84
|
+
code: STRING_TEST,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
code: TEMPLATE_TEST,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
code: STRING_WITH_CARD_NUMBER_THAT_DOESNT_PASS_LUHN_CHECK,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
code: CONTAINS_A_PASSING_CARD_NUMBER,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
code: CONTAINS_A_PASSING_CARD_NUMBER_IN_COMMENT,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
code: CONTAINS_PASSING_BUT_INVALID_0_PREFIX_CARD_NUMBER_IN_STRING,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
code: CONTAINS_PASSING_BUT_INVALID_1_PREFIX_CARD_NUMBER_IN_STRING,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
code: CONTAINS_PASSING_BUT_INVALID_7_PREFIX_CARD_NUMBER_IN_STRING,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
code: CONTAINS_PASSING_BUT_INVALID_8_PREFIX_CARD_NUMBER_IN_STRING,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
code: CONTAINS_PASSING_BUT_INVALID_9_PREFIX_CARD_NUMBER_IN_STRING,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
invalid: [
|
|
115
|
+
{
|
|
116
|
+
code: CONTAINS_CARD_NUMBER_IN_NUMBER,
|
|
117
|
+
errors: [CARD_NUMBER_FOUND_MSG],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
code: CONTAINS_SEVERAL_CARD_NUMBERS_IN_STRING,
|
|
121
|
+
errors: [CARD_NUMBERS_FOUND_MSG],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
code: CONTAINS_CARD_NUMBER_IN_COMMENT,
|
|
125
|
+
errors: [CARD_NUMBER_FOUND_MSG],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
code: CONTAINS_SEVERAL_CARD_NUMBERS_IN_COMMENT,
|
|
129
|
+
errors: [CARD_NUMBERS_FOUND_MSG],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=no-card-numbers.spec.js.map
|