eslint-plugin-no-pii 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +45 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +28 -0
- package/dist/internal/create-pii-rule.d.ts +15 -0
- package/dist/internal/create-pii-rule.js +57 -0
- package/dist/rules/no-dob.d.ts +2 -0
- package/dist/rules/no-dob.js +9 -0
- package/dist/rules/no-email.d.ts +2 -0
- package/dist/rules/no-email.js +6 -0
- package/dist/rules/no-ip.d.ts +2 -0
- package/dist/rules/no-ip.js +9 -0
- package/dist/rules/no-phone-number.d.ts +2 -0
- package/dist/rules/no-phone-number.js +15 -0
- package/package.json +66 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-current Łukasz Wójcik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# eslint-plugin-no-pii
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PII linting rules for ESLint 10.
|
|
4
|
+
|
|
5
|
+
Fork of [shiva-hack/eslint-plugin-pii](https://github.com/shiva-hack/eslint-plugin-pii), modernized and updated for ESLint 10+.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ npm install eslint eslint-plugin-no-pii --save-dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Recommended Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// eslint.config.js (ESM, or use dynamic import() from CommonJS)
|
|
17
|
+
import pii from "eslint-plugin-no-pii";
|
|
18
|
+
|
|
19
|
+
export default [pii.configs.recommended];
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Custom Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// eslint.config.js (ESM, or use dynamic import() from CommonJS)
|
|
26
|
+
import pii from "eslint-plugin-no-pii";
|
|
27
|
+
|
|
28
|
+
export default [
|
|
29
|
+
{
|
|
30
|
+
plugins: { pii },
|
|
31
|
+
rules: {
|
|
32
|
+
"pii/no-email": "error",
|
|
33
|
+
"pii/no-dob": "warn",
|
|
34
|
+
"pii/no-ip": "error",
|
|
35
|
+
"pii/no-phone-number": "error",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Supported Rules
|
|
42
|
+
|
|
43
|
+
- `pii/no-email` - enforces no email in comments or string literals
|
|
44
|
+
- `pii/no-dob` - enforces no birth date in comments or string literals
|
|
45
|
+
- `pii/no-ip` - enforces no IP address in comments or string literals
|
|
46
|
+
- `pii/no-phone-number` - enforces no phone numbers in comments or string literals
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import noDob from "./rules/no-dob.js";
|
|
3
|
+
import noEmail from "./rules/no-email.js";
|
|
4
|
+
import noIp from "./rules/no-ip.js";
|
|
5
|
+
import noPhoneNumber from "./rules/no-phone-number.js";
|
|
6
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
7
|
+
const plugin = {
|
|
8
|
+
meta: { name: pkg.name, version: pkg.version },
|
|
9
|
+
rules: {
|
|
10
|
+
"no-dob": noDob,
|
|
11
|
+
"no-email": noEmail,
|
|
12
|
+
"no-ip": noIp,
|
|
13
|
+
"no-phone-number": noPhoneNumber,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
plugin.configs = {
|
|
17
|
+
recommended: {
|
|
18
|
+
name: "pii/recommended",
|
|
19
|
+
plugins: { pii: plugin },
|
|
20
|
+
rules: {
|
|
21
|
+
"pii/no-email": "error",
|
|
22
|
+
"pii/no-dob": "warn",
|
|
23
|
+
"pii/no-ip": "error",
|
|
24
|
+
"pii/no-phone-number": "error",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export default plugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared factory for rules that flag PII patterns in comments and string literals.
|
|
3
|
+
*/
|
|
4
|
+
import type { Rule } from "eslint";
|
|
5
|
+
interface PiiRuleOptions {
|
|
6
|
+
description: string;
|
|
7
|
+
/** Human readable name used in messages, e.g. "IP address". */
|
|
8
|
+
subject: string;
|
|
9
|
+
/** Non-global patterns (stateless `.test`). */
|
|
10
|
+
patterns: RegExp[];
|
|
11
|
+
/** Also test `<identifier> <literal>` pairs. */
|
|
12
|
+
checkDeclarators?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createPiiRule({ description, subject, patterns, checkDeclarators, }: PiiRuleOptions): Rule.RuleModule;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared factory for rules that flag PII patterns in comments and string literals.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Report location that ignores `eslint-disable` comments (column -1 forces the
|
|
6
|
+
* report to be treated as covering the whole start line).
|
|
7
|
+
*/
|
|
8
|
+
const toForceLocation = (loc) => ({
|
|
9
|
+
start: { line: loc.start.line, column: -1 },
|
|
10
|
+
end: loc.end,
|
|
11
|
+
});
|
|
12
|
+
export function createPiiRule({ description, subject, patterns, checkDeclarators = false, }) {
|
|
13
|
+
const matches = (value) => patterns.some((pattern) => pattern.test(value));
|
|
14
|
+
return {
|
|
15
|
+
meta: {
|
|
16
|
+
type: "problem",
|
|
17
|
+
docs: { description },
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
comment: `PII Violation: cannot use ${subject} in a comment`,
|
|
21
|
+
literal: `PII Violation: cannot use ${subject} in a literal`,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
create(context) {
|
|
25
|
+
const { sourceCode } = context;
|
|
26
|
+
const report = (loc, messageId) => {
|
|
27
|
+
if (loc)
|
|
28
|
+
context.report({ loc: toForceLocation(loc), messageId });
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
Program() {
|
|
32
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
33
|
+
if (matches(comment.value)) {
|
|
34
|
+
report(comment.loc, "comment");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
Literal(node) {
|
|
39
|
+
if (typeof node.value === "string" && matches(node.value)) {
|
|
40
|
+
report(node.loc, "literal");
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
...(checkDeclarators && {
|
|
44
|
+
VariableDeclarator(node) {
|
|
45
|
+
if (node.id.type !== "Identifier")
|
|
46
|
+
return;
|
|
47
|
+
if (node.init?.type !== "Literal")
|
|
48
|
+
return;
|
|
49
|
+
if (matches(`${node.id.name} ${node.init.value}`)) {
|
|
50
|
+
report(node.loc, "literal");
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPiiRule } from "../internal/create-pii-rule.js";
|
|
2
|
+
export default createPiiRule({
|
|
3
|
+
description: "enforces no date of birth in comments or string literals",
|
|
4
|
+
subject: "date of birth",
|
|
5
|
+
checkDeclarators: true,
|
|
6
|
+
patterns: [
|
|
7
|
+
/\b(birth|birthdate|birthday|dob|born)\W+(?:\w+\W+){0,5}?(?<REDACT>(\d{4}|\d{1,2})[/-]\d{1,2}[/-](\d{4}|\d{1,2}))\b/,
|
|
8
|
+
],
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPiiRule } from "../internal/create-pii-rule.js";
|
|
2
|
+
export default createPiiRule({
|
|
3
|
+
description: "enforces no ip address in comments or string literals",
|
|
4
|
+
subject: "IP address",
|
|
5
|
+
patterns: [
|
|
6
|
+
/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/,
|
|
7
|
+
/\b([\d\w]{4}|0)(:([\d\w]{4}|0)){7}\b/,
|
|
8
|
+
],
|
|
9
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createPiiRule } from "../internal/create-pii-rule.js";
|
|
2
|
+
export default createPiiRule({
|
|
3
|
+
description: "enforces no phone numbers in comments or string literals",
|
|
4
|
+
subject: "phone number",
|
|
5
|
+
patterns: [
|
|
6
|
+
// France
|
|
7
|
+
/\b([0O]?[1lI][1lI])?[3E][3E][0O]?[\dOIlZEASB]{9}\b/,
|
|
8
|
+
// Germany
|
|
9
|
+
/\b[\d\w]\d{2}[\d\w]{6}\d[\d\w]\b/,
|
|
10
|
+
// UK
|
|
11
|
+
/(((\+44)? ?(\(0\))? ?)|(0))( ?[0-9]{3,4}){3}/,
|
|
12
|
+
// US
|
|
13
|
+
/\b((\+|\b)[1l][-. ])?\(?\b[\dOlZSB]{3,5}([-. ]|\) ?)[\dOlZSB]{3}[-. ][\dOlZSB]{4}\b/,
|
|
14
|
+
],
|
|
15
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-no-pii",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "PII linting rules for ESLint 10",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin",
|
|
9
|
+
"pii"
|
|
10
|
+
],
|
|
11
|
+
"author": "Łukasz Wójcik",
|
|
12
|
+
"homepage": "https://github.com/lwojcik/eslint-plugin-no-pii",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prepare": "husky",
|
|
15
|
+
"commit": "cz",
|
|
16
|
+
"format": "prettier --write .",
|
|
17
|
+
"format:check": "prettier --check .",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"test": "node --test \"tests/**/*.ts\"",
|
|
20
|
+
"release": "HUSKY=0 GITHUB_TOKEN=$(gh auth token) release-it --no-increment --no-git.commit",
|
|
21
|
+
"release:prepare": "scripts/release-prepare.sh",
|
|
22
|
+
"build": "tsc -p tsconfig.build.json",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"prepack": "rm -rf dist && npm run build"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20.19.0"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"url": "git+https://github.com/lwojcik/eslint-plugin-no-pii.git"
|
|
31
|
+
},
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"eslint": ">=9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@commitlint/cli": "21.2.4",
|
|
38
|
+
"@commitlint/config-conventional": "21.2.4",
|
|
39
|
+
"@eslint/js": "^10.0.1",
|
|
40
|
+
"@release-it/conventional-changelog": "^12.0.2",
|
|
41
|
+
"@types/node": "^26.6.6",
|
|
42
|
+
"commitizen": "4.3.2",
|
|
43
|
+
"cz-conventional-changelog": "3.3.0",
|
|
44
|
+
"eslint": "^10.0.0",
|
|
45
|
+
"globals": "^17.14.0",
|
|
46
|
+
"husky": "9.1.7",
|
|
47
|
+
"prettier": "^3.0.0",
|
|
48
|
+
"release-it": "^21.1.2",
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
|
+
"typescript-eslint": "^8.73.0"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"type": "module",
|
|
56
|
+
"exports": {
|
|
57
|
+
".": {
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
59
|
+
"default": "./dist/index.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"config": {
|
|
63
|
+
"commitizen": {
|
|
64
|
+
"path": "cz-conventional-changelog"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"types": "./dist/index.d.ts"
|
|
68
|
+
}
|