@checkdigit/eslint-plugin 4.1.0-PR.32-b8ce → 4.1.1

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,4 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
2
  declare const _default: Rule.RuleModule;
3
3
  export default _default;
4
- //# sourceMappingURL=file-path-comment.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=file-path-comment.spec.d.ts.map
package/dist/index.d.ts CHANGED
@@ -22,4 +22,3 @@ declare const _default: {
22
22
  };
23
23
  };
24
24
  export default _default;
25
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,38 +1,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
1
+ "use strict";const e="CARD_NUMBER_FOUND",t="CARD_NUMBERS_FOUND",n=/\d{15,19}/gmu,o=["4111111111111111","111111111111111","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000"];function i(i,r,a,s){const l=i.match(n);if(null===l)return;const d=l.filter((e=>e.split("").reverse().map((e=>parseInt(e,10))).reduce(((e,t,n)=>{let o=t;return n%2==1&&(o*=2,o>9&&(o=o%10+1)),e+o}),0)%10==0&&-1===o.indexOf(e)&&"0"!==e[0]&&"1"!==e[0]&&"7"!==e[0]&&"8"!==e[0]&&"9"!==e[0]));1===d.length?void 0!==a?r.report({messageId:e,data:{number:d[0]},node:a}):void 0!==s&&r.report({messageId:e,data:{number:d[0]},loc:{start:s.start,end:s.end}}):d.length>1&&(void 0!==a?r.report({messageId:t,data:{numbers:l.join(", ")},node:a}):void 0!==s&&r.report({messageId:t,data:{numbers:l.join(", ")},loc:{start:s.start,end:s.end}}))}const r="UUID_FOUND",a="UUIDS_FOUND",s=/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}/gmu;function l(e,t,n,o){const i=e.match(s);null!==i&&(1===i.length?void 0!==n?t.report({messageId:r,data:{uuid:i[0]??""},node:n}):void 0!==o&&t.report({messageId:r,data:{uuid:i[0]??""},loc:{start:o.start,end:o.end}}):i.length>1&&(void 0!==n?t.report({messageId:a,data:{uuids:i.join(", ")},node:n}):void 0!==o&&t.report({messageId:a,data:{uuids:i.join(", ")},loc:{start:o.start,end:o.end}})))}var d={rules:{"file-path-comment":{meta:{type:"suggestion",docs:{description:"Validate that first line of file is a path to the file",url:"https://github.com/checkdigit/eslint-plugin"},fixable:"code"},create(e){const t=e.getSourceCode().getLines()[0],n=e.getFilename().split("src/")[1];if(void 0===n)return{};if(t.startsWith("//")){const o=t.split("// ")[1];n!==o&&e.report({loc:{start:{line:0,column:0},end:{line:0,column:1}},message:"first line is a comment but is not a path to the file",fix:e=>e.replaceTextRange([0,t.length],`// ${n}`)})}else t.startsWith("/*")?e.report({loc:{start:{line:0,column:0},end:{line:0,column:1}},message:"first line cannot be a block comment",fix:e=>e.insertTextBeforeRange([0,0],`// ${n}\n\n`)}):e.report({loc:{start:{line:0,column:0},end:{line:0,column:1}},message:"first line is not a comment with the file path",fix:e=>e.insertTextBeforeRange([0,0],`// ${n}\n\n`)});return{}}},"no-card-numbers":{meta:{type:"problem",docs:{description:"Detects if a luhn passing card number",url:"https://github.com/checkdigit/eslint-plugin"},messages:{[e]:'Valid card number: "{{ number }}"',[t]:'Multiple valid card numbers found: "{{ numbers }}"'}},create:e=>(e.getSourceCode().getAllComments().forEach((t=>{void 0!==t.loc&&null!==t.loc&&i(t.value,e,void 0,t.loc)})),{Literal(t){if(void 0===t.value)return;if("string"!=typeof t.value&&"number"!=typeof t.value)return;i(`${t.value}`,e,t)},TemplateElement(t){t.value&&"string"==typeof t.value.cooked&&i(t.value.cooked,e,t)}})},"no-uuid":{meta:{type:"problem",docs:{description:"Detects if a string literal contains a UUID",url:"https://github.com/checkdigit/eslint-plugin"},messages:{[r]:'UUID found: "{{ uuid }}"',[a]:'Multiple UUIDs found: "{{ uuids }}"'}},create:e=>(e.getSourceCode().getAllComments().forEach((t=>{void 0!==t.loc&&null!==t.loc&&l(t.value,e,void 0,t.loc)})),{Literal(t){if(void 0===t.value)return;if("string"!=typeof t.value)return;l(`${t.value}`,e,t)},TemplateElement(t){t.value&&"string"==typeof t.value.cooked&&l(t.value.cooked,e,t)}})}},configs:{all:{rules:{"@checkdigit/no-card-numbers":"error","@checkdigit/file-path-comment":"error","@checkdigit/no-uuid":"error"}},recommended:{rules:{"@checkdigit/no-card-numbers":"error","@checkdigit/file-path-comment":"off","@checkdigit/no-uuid":"error"}}}};module.exports=d;
2
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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"]}
1
+ {"version":3,"file":"index.js","sources":["../src/no-card-numbers.ts","../src/no-uuid.ts","../src/index.ts","../src/file-path-comment.ts"],"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","// no-uuid.ts\n\n/*\n * Copyright (c) 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 UUID_FOUND = 'UUID_FOUND';\nconst UUIDS_FOUND = 'UUIDS_FOUND';\nconst uuidRegex = /[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}/gmu;\n\nfunction checkForUuid(value: string, context: Rule.RuleContext, node?: Node, loc?: SourceLocation) {\n const matches = value.match(uuidRegex);\n if (matches === null) {\n return;\n }\n if (matches.length === 1) {\n if (node !== undefined) {\n context.report({\n messageId: UUID_FOUND,\n data: {\n uuid: matches[0] ?? '',\n },\n node,\n });\n } else if (loc !== undefined) {\n context.report({\n messageId: UUID_FOUND,\n data: {\n uuid: matches[0] ?? '',\n },\n loc: {\n start: loc.start,\n end: loc.end,\n },\n });\n }\n } else if (matches.length > 1) {\n if (node !== undefined) {\n context.report({\n messageId: UUIDS_FOUND,\n data: {\n uuids: matches.join(', '),\n },\n node,\n });\n } else if (loc !== undefined) {\n context.report({\n messageId: UUIDS_FOUND,\n data: {\n uuids: 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 string literal contains a UUID',\n url: 'https://github.com/checkdigit/eslint-plugin',\n },\n messages: {\n [UUID_FOUND]: `UUID found: \"{{ uuid }}\"`,\n [UUIDS_FOUND]: `Multiple UUIDs found: \"{{ uuids }}\"`,\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 checkForUuid(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') {\n return;\n }\n const value = `${node.value}`;\n checkForUuid(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 checkForUuid(node.value.cooked, context, node);\n },\n };\n },\n} as Rule.RuleModule;\n","// 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","// 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"],"names":["CARD_NUMBER_FOUND","CARD_NUMBERS_FOUND","cardNumberRegex","allowCardNumbers","checkForCardNumbers","value","context","node","loc","matches","match","cardNumbers","filter","split","reverse","map","digit","parseInt","reduce","previousValue","currentValue","index","indexOf","length","undefined","report","messageId","data","number","start","end","numbers","join","UUID_FOUND","UUIDS_FOUND","uuidRegex","checkForUuid","uuid","uuids","rules","meta","type","docs","description","url","fixable","create","firstLine","getSourceCode","getLines","expectedPath","getFilename","startsWith","actualComment","line","column","message","fix","fixer","replaceTextRange","insertTextBeforeRange","messages","getAllComments","forEach","comment","Literal","TemplateElement","cooked","configs","all","recommended"],"mappings":"aAWA,MAAMA,EAAoB,oBACpBC,EAAqB,qBACrBC,EAAkB,eAClBC,EAAmB,CACvB,mBACA,kBACA,kBACA,mBACA,oBACA,qBACA,uBAyBF,SAASC,EAAoBC,EAAeC,EAA2BC,EAAaC,GAClF,MAAMC,EAAUJ,EAAMK,MAAMR,GAC5B,GAAgB,OAAZO,EACF,OAEF,MAAME,EAAcF,EAAQG,QACzBF,GACWA,EA1BTG,MAAM,IACNC,UACAC,KAAKC,GAAUC,SAASD,EAAO,MAC/BE,QAAO,CAACC,EAAeC,EAAcC,KACpC,IAAIhB,EAAQe,EAQZ,OAPIC,EAAQ,GAAM,IAChBhB,GAAS,EAELA,EAAQ,IACVA,EAASA,EAAQ,GAAM,IAGpBc,EAAgBd,CAAK,GAC3B,GACH,IACF,IAYuC,IAArCF,EAAiBmB,QAAQZ,IAEZ,MAAbA,EAAM,IACO,MAAbA,EAAM,IACO,MAAbA,EAAM,IACO,MAAbA,EAAM,IACO,MAAbA,EAAM,KAEiB,IAAvBC,EAAYY,YACDC,IAATjB,EACFD,EAAQmB,OAAO,CACbC,UAAW1B,EACX2B,KAAM,CACJC,OAAQjB,EAAY,IAEtBJ,cAEeiB,IAARhB,GACTF,EAAQmB,OAAO,CACbC,UAAW1B,EACX2B,KAAM,CACJC,OAAQjB,EAAY,IAEtBH,IAAK,CACHqB,MAAOrB,EAAIqB,MACXC,IAAKtB,EAAIsB,OAINnB,EAAYY,OAAS,SACjBC,IAATjB,EACFD,EAAQmB,OAAO,CACbC,UAAWzB,EACX0B,KAAM,CACJI,QAAStB,EAAQuB,KAAK,OAExBzB,cAEeiB,IAARhB,GACTF,EAAQmB,OAAO,CACbC,UAAWzB,EACX0B,KAAM,CACJI,QAAStB,EAAQuB,KAAK,OAExBxB,IAAK,CACHqB,MAAOrB,EAAIqB,MACXC,IAAKtB,EAAIsB,OAKnB,CC9FA,MAAMG,EAAa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KAAqC,OAAhBwD,EAAQxD,KACvC4B,EAAa4B,EAAQ3D,MAAOC,OAASkB,EAAWwC,EAAQxD,IACzD,IAEI,CACLyD,QAAQ1D,GACN,QAAmBiB,IAAfjB,EAAKF,MACP,OAEF,GAA0B,iBAAfE,EAAKF,MACd,OAGF+B,EADc,GAAG7B,EAAKF,QACFC,EAASC,EAC9B,EACD2D,gBAAgB3D,GACTA,EAAKF,OAGuB,iBAAtBE,EAAKF,MAAM8D,QAGtB/B,EAAa7B,EAAKF,MAAM8D,OAAQ7D,EAASC,EAC1C,MCvFL6D,QAAS,CACPC,IAAK,CACH9B,MAAO,CACL,8BAA+B,QAC/B,gCAAiC,QACjC,sBAAuB,UAG3B+B,YAAa,CACX/B,MAAO,CACL,8BAA+B,QAC/B,gCAAiC,MACjC,sBAAuB"}
@@ -1,4 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
2
  declare const _default: Rule.RuleModule;
3
3
  export default _default;
4
- //# sourceMappingURL=no-card-numbers.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=no-card-numbers.spec.d.ts.map
package/dist/no-uuid.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
2
  declare const _default: Rule.RuleModule;
3
3
  export default _default;
4
- //# sourceMappingURL=no-uuid.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=no-uuid.spec.d.ts.map
package/package.json CHANGED
@@ -1 +1,63 @@
1
- {"name":"@checkdigit/eslint-plugin","version":"4.1.0-PR.32-b8ce","description":"Check Digit eslint plugins","prettier":"@checkdigit/prettier-config","main":"dist/index.js","keywords":["eslint","eslintplugin"],"engines":{"node":">=16"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/eslint-plugin.git"},"author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/eslint-plugin/issues"},"homepage":"https://github.com/checkdigit/eslint-plugin#readme","peerDependencies":{"eslint":">=8"},"devDependencies":{"@checkdigit/jest-config":"^2.2.1","@checkdigit/prettier-config":"^3.4.0","@checkdigit/typescript-config":"^3.3.0","@types/eslint":"^8.37.0","@typescript-eslint/eslint-plugin":"^5.59.7","@typescript-eslint/parser":"^5.59.7","eslint-config-prettier":"^8.8.0","eslint-plugin-deprecate":"^0.7.0","eslint-plugin-eslint-plugin":"^5.1.0","eslint-plugin-import":"^2.27.5","eslint-plugin-no-only-tests":"^3.1.0","eslint-plugin-no-secrets":"^0.8.9","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"^0.19.0"},"scripts":{"postversion":"git push && git push --tags","lint:fix":"eslint -f unix --ext .ts src --fix","lint":"eslint -f unix --ext .ts src","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","ci:compile":"tsc --noEmit","ci:test":"jest --coverage=false","ci:coverage":"jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier"},"jest":{"preset":"@checkdigit/jest-config"},"files":["dist","SECURITY.md","/src/"]}
1
+ {
2
+ "name": "@checkdigit/eslint-plugin",
3
+ "version": "4.1.1",
4
+ "description": "Check Digit eslint plugins",
5
+ "prettier": "@checkdigit/prettier-config",
6
+ "main": "dist/index.js",
7
+ "keywords": [
8
+ "eslint",
9
+ "eslintplugin"
10
+ ],
11
+ "engines": {
12
+ "node": ">=16"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/checkdigit/eslint-plugin.git"
17
+ },
18
+ "author": "Check Digit, LLC",
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://github.com/checkdigit/eslint-plugin/issues"
22
+ },
23
+ "homepage": "https://github.com/checkdigit/eslint-plugin#readme",
24
+ "peerDependencies": {
25
+ "eslint": ">=8"
26
+ },
27
+ "devDependencies": {
28
+ "@checkdigit/jest-config": "^2.2.1",
29
+ "@checkdigit/prettier-config": "^3.4.0",
30
+ "@checkdigit/typescript-config": "^3.3.0",
31
+ "@types/eslint": "^8.37.0",
32
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
33
+ "@typescript-eslint/parser": "^5.59.7",
34
+ "eslint-config-prettier": "^8.8.0",
35
+ "eslint-plugin-deprecate": "^0.7.0",
36
+ "eslint-plugin-eslint-plugin": "^5.1.0",
37
+ "eslint-plugin-import": "^2.27.5",
38
+ "eslint-plugin-no-only-tests": "^3.1.0",
39
+ "eslint-plugin-no-secrets": "^0.8.9",
40
+ "eslint-plugin-node": "^11.1.0",
41
+ "eslint-plugin-sonarjs": "^0.19.0"
42
+ },
43
+ "scripts": {
44
+ "postversion": "git push && git push --tags",
45
+ "lint:fix": "eslint -f unix --ext .ts src --fix",
46
+ "lint": "eslint -f unix --ext .ts src",
47
+ "prettier": "prettier --ignore-path .gitignore --list-different .",
48
+ "prettier:fix": "prettier --ignore-path .gitignore --write .",
49
+ "test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style",
50
+ "ci:compile": "tsc --noEmit",
51
+ "ci:test": "jest --coverage=false",
52
+ "ci:coverage": "jest --coverage=true",
53
+ "ci:lint": "npm run lint",
54
+ "ci:style": "npm run prettier"
55
+ },
56
+ "jest": {
57
+ "preset": "@checkdigit/jest-config"
58
+ },
59
+ "files": [
60
+ "dist",
61
+ "SECURITY.md"
62
+ ]
63
+ }
@@ -1 +0,0 @@
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"}
@@ -1,86 +0,0 @@
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
@@ -1 +0,0 @@
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,6CA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aACJ;SACF;aAAM;YACL,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAChD,IAAI,YAAY,KAAK,aAAa,EAAE;gBAClC,OAAO,CAAC,MAAM,CAAC;oBACb,GAAG,EAAE;wBACH,KAAK,EAAE;4BACL,IAAI,EAAE,CAAC;4BACP,MAAM,EAAE,CAAC;yBACV;wBACD,GAAG,EAAE;4BACH,IAAI,EAAE,CAAC;4BACP,MAAM,EAAE,CAAC;yBACV;qBACF;oBACD,OAAO,EAAE,uDAAuD;oBAChE,GAAG,CAAC,KAAqB;wBACvB,OAAO,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,YAAY,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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-path-comment.spec.d.ts","sourceRoot":"","sources":["../src/file-path-comment.spec.ts"],"names":[],"mappings":""}
@@ -1,72 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAYA,wBAsBE"}
@@ -1 +0,0 @@
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"}
@@ -1,138 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"no-card-numbers.js","sourceRoot":"","sources":["../src/no-card-numbers.ts"],"names":[],"mappings":";AAAA,qBAAqB;;AAWrB,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAChD,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,gBAAgB,GAAG;IACvB,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,mBAAmB;IACnB,oBAAoB;IACpB,qBAAqB;CACtB,CAAC;AAEF,SAAS,SAAS,CAAC,UAAkB;IACnC,OAAO,CACL,UAAU;SACP,KAAK,CAAC,EAAE,CAAC;SACT,OAAO,EAAE;SACT,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SACnC,MAAM,CAAC,CAAC,aAAa,EAAE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E7C,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI,EAAE;gBACrD,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;aACrE;QACH,CAAC,CAAC,CAAC;QACH,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;oBAC5B,OAAO;iBACR;gBACD,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;oBACpE,OAAO;iBACR;gBACD,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC9B,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAC5C,CAAC;YACD,eAAe,CAAC,IAAI;gBAClB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;oBACf,OAAO;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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"no-card-numbers.spec.d.ts","sourceRoot":"","sources":["../src/no-card-numbers.spec.ts"],"names":[],"mappings":""}