@swift-rust/eslint-plugin 0.2.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/README.md +19 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/index.d.ts +9 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +4 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/smoke.test.d.ts +2 -0
- package/dist/smoke.test.d.ts.map +1 -0
- package/dist/smoke.test.js +6 -0
- package/dist/smoke.test.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @swift-rust/eslint-plugin
|
|
2
|
+
|
|
3
|
+
Custom ESLint rules for swift-rust.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
- `@swift-rust/no-img-element` — disallow raw `<img>` tags. Use the `<Image>` component.
|
|
8
|
+
- `@swift-rust/no-anchor-target-blank` — require `rel="noopener"` on `<a target="_blank">`.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// eslint.config.js
|
|
14
|
+
import swiftRustPlugin from "@swift-rust/eslint-plugin";
|
|
15
|
+
|
|
16
|
+
export default [
|
|
17
|
+
swiftRustPlugin.configs.recommended,
|
|
18
|
+
];
|
|
19
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
3
|
+
export declare const configs: {
|
|
4
|
+
recommended: {
|
|
5
|
+
plugins: string[];
|
|
6
|
+
rules: {
|
|
7
|
+
"@swift-rust/no-img-element": string;
|
|
8
|
+
"@swift-rust/no-anchor-target-blank": string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare const _default: {
|
|
13
|
+
rules: Record<string, Rule.RuleModule>;
|
|
14
|
+
configs: {
|
|
15
|
+
recommended: {
|
|
16
|
+
plugins: string[];
|
|
17
|
+
rules: {
|
|
18
|
+
"@swift-rust/no-img-element": string;
|
|
19
|
+
"@swift-rust/no-anchor-target-blank": string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
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":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAmEnC,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAGjD,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;;CAQnB,CAAC;;;;;;;;;;;;;AAEF,wBAAkC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const noServerSideImageRule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "Disallow raw <img> tags in favor of the <Image> component.",
|
|
6
|
+
},
|
|
7
|
+
schema: [],
|
|
8
|
+
messages: {
|
|
9
|
+
useImage: 'Use the <Image> component from "swift-rust/image" instead of a raw <img> tag.',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
JSXOpeningElement(node) {
|
|
15
|
+
const el = node;
|
|
16
|
+
if (el.name?.type === "JSXIdentifier" && el.name.name === "img") {
|
|
17
|
+
context.report({ node: node, messageId: "useImage" });
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const noAnchorTargetBlankRule = {
|
|
24
|
+
meta: {
|
|
25
|
+
type: "suggestion",
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Require rel="noopener" on <a target="_blank"> tags.',
|
|
28
|
+
},
|
|
29
|
+
schema: [],
|
|
30
|
+
messages: {
|
|
31
|
+
missingRel: 'Anchor with target="_blank" must include rel="noopener".',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
create(context) {
|
|
35
|
+
return {
|
|
36
|
+
JSXOpeningElement(node) {
|
|
37
|
+
const el = node;
|
|
38
|
+
if (el.name?.name !== "a")
|
|
39
|
+
return;
|
|
40
|
+
const hasTarget = (el.attributes ?? []).some((a) => a.name?.name === "target");
|
|
41
|
+
const hasRel = (el.attributes ?? []).some((a) => {
|
|
42
|
+
if (a.name?.name !== "rel")
|
|
43
|
+
return false;
|
|
44
|
+
const v = a.value;
|
|
45
|
+
return (v?.type === "Literal" && typeof v.value === "string" && v.value.includes("noopener"));
|
|
46
|
+
});
|
|
47
|
+
if (hasTarget && !hasRel) {
|
|
48
|
+
context.report({ node: node, messageId: "missingRel" });
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export const rules = {
|
|
55
|
+
"no-img-element": noServerSideImageRule,
|
|
56
|
+
"no-anchor-target-blank": noAnchorTargetBlankRule,
|
|
57
|
+
};
|
|
58
|
+
export const configs = {
|
|
59
|
+
recommended: {
|
|
60
|
+
plugins: ["@swift-rust"],
|
|
61
|
+
rules: {
|
|
62
|
+
"@swift-rust/no-img-element": "error",
|
|
63
|
+
"@swift-rust/no-anchor-target-blank": "warn",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export default { rules, configs };
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,MAAM,qBAAqB,GAAoB;IAC7C,IAAI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,KAAK;wBAAE,OAAO,KAAK,CAAC;oBACzC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;oBAClB,OAAO,CACL,CAAC,EAAE,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CACrF,CAAC;gBACJ,CAAC,CAAC,CAAC;gBACH,IAAI,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;oBACzB,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAa,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAoC;IACpD,gBAAgB,EAAE,qBAAqB;IACvC,wBAAwB,EAAE,uBAAuB;CAClD,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,WAAW,EAAE;QACX,OAAO,EAAE,CAAC,aAAa,CAAC;QACxB,KAAK,EAAE;YACL,4BAA4B,EAAE,OAAO;YACrC,oCAAoC,EAAE,MAAM;SAC7C;KACF;CACF,CAAC;AAEF,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
3
|
+
export declare const configs: {};
|
|
4
|
+
declare const _default: {
|
|
5
|
+
rules: Record<string, Rule.RuleModule>;
|
|
6
|
+
configs: {};
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAM,CAAC;AAEzD,eAAO,MAAM,OAAO,IAAK,CAAC;;;;;AAE1B,wBAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAoC,EAAE,CAAC;AAEzD,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC;AAE1B,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smoke.test.d.ts","sourceRoot":"","sources":["../src/smoke.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smoke.test.js","sourceRoot":"","sources":["../src/smoke.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,SAAS,CAAC;AAE/B,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACrD,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@swift-rust/eslint-plugin",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "ESLint rules for swift-rust projects.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
21
|
+
"lint": "biome check --no-errors-on-unmatched $(pwd)/src",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"clean": "rm -rf dist .turbo"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"eslint": "^8.57.0 || ^9.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/eslint": "^8.56.0",
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"typescript": "^6.0.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/swift-rust/swift-rust.git",
|
|
39
|
+
"directory": "packages/eslint-plugin"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/swift-rust/swift-rust/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://swift-rust.dev"
|
|
45
|
+
}
|