Skip to content

Commit bf5b002

Browse files
committed
feat(tsl-module): add noDuplicateImport rule to disallow duplicate imports
chore(tsl-module): initialize package.json and add necessary configurations feat(tsl-module): implement no-duplicate-import rule logic docs(tsl-module): add README and documentation for noDuplicateImport variable chore(tsl-module): add TypeScript configuration and build scripts chore: update tsdown to version 0.19.0-beta.2 in pnpm-lock.yaml
1 parent 0d5750d commit bf5b002

File tree

16 files changed

+1104
-18
lines changed

16 files changed

+1104
-18
lines changed

.pkgs/function-rules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"devDependencies": {
2727
"eslint": "^9.39.2",
28-
"tsdown": "^0.19.0-beta.1"
28+
"tsdown": "^0.19.0-beta.2"
2929
},
3030
"peerDependencies": {
3131
"eslint": "^9.39.2",

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "git+https://github.com/Rel1cx/dx.git"
1313
},
1414
"license": "MIT",
15-
"author": "Rel1cx<rel1cx@proton.me>",
15+
"author": "Rel1cx<let@ik.me>",
1616
"type": "module",
1717
"scripts": {
1818
"build": "pnpm run build:pkgs && pnpm run build:packages",
@@ -28,6 +28,7 @@
2828
"lint:publish": "pnpm m run lint:publish",
2929
"lint:ts": "pnpm m run lint:ts",
3030
"prepare": "pnpm run build",
31+
"test": "pnpm m run test",
3132
"update:version": "tsx ./scripts/update-version.ts"
3233
},
3334
"devDependencies": {
@@ -52,7 +53,7 @@
5253
"sort-package-json": "^3.6.0",
5354
"tinyglobby": "^0.2.15",
5455
"ts-pattern": "^5.9.0",
55-
"tsdown": "^0.19.0-beta.1",
56+
"tsdown": "^0.19.0-beta.2",
5657
"tsx": "^4.21.0",
5758
"typedoc": "^0.28.15",
5859
"typedoc-plugin-markdown": "^4.9.0",

packages/eff/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "git+https://github.com/Rel1cx/dx.git"
1212
},
1313
"license": "MIT",
14-
"author": "Rel1cx<rel1cx@proton.me>",
14+
"author": "Rel1cx<let@ik.me>",
1515
"type": "module",
1616
"exports": {
1717
".": "./dist/index.js",

packages/eslint-plugin-function-rule/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "git+https://github.com/Rel1cx/dx.git"
1212
},
1313
"license": "MIT",
14-
"author": "Rel1cx<rel1cx@proton.me>",
14+
"author": "Rel1cx<let@ik.me>",
1515
"sideEffects": false,
1616
"type": "module",
1717
"exports": {

packages/eslint-plugin-function/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "git+https://github.com/Rel1cx/dx.git"
1313
},
1414
"license": "MIT",
15-
"author": "Rel1cx<rel1cx@proton.me>",
15+
"author": "Rel1cx<let@ik.me>",
1616
"sideEffects": false,
1717
"type": "module",
1818
"exports": {
@@ -49,7 +49,7 @@
4949
"@typescript-eslint/rule-tester": "^8.51.0",
5050
"dedent": "^1.7.1",
5151
"eslint": "^9.39.2",
52-
"tsdown": "^0.19.0-beta.1"
52+
"tsdown": "^0.19.0-beta.2"
5353
},
5454
"peerDependencies": {
5555
"eslint": "^9.39.2",

packages/tsl-module/docs/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# tsl-module
2+
3+
## Variables
4+
5+
| Variable | Description |
6+
| ------ | ------ |
7+
| [noDuplicateImport](variables/noDuplicateImport.md) | Rule to disallow duplicate imports from the same module. |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[tsl-module](../README.md) / noDuplicateImport
2+
3+
# Variable: noDuplicateImport()
4+
5+
```ts
6+
const noDuplicateImport: (options?: "off") => Rule<unknown>;
7+
```
8+
9+
Rule to disallow duplicate imports from the same module.
10+
11+
## Parameters
12+
13+
| Parameter | Type |
14+
| ------ | ------ |
15+
| `options?` | `"off"` |
16+
17+
## Returns
18+
19+
`Rule`\<`unknown`\>
20+
21+
## Examples
22+
23+
```ts
24+
// Incorrect
25+
import { A } from 'module';
26+
import { B } from 'module';
27+
```
28+
29+
```ts
30+
// Incorrect
31+
import type { A } from 'module';
32+
import type { B } from 'module';
33+
```
34+
35+
```ts
36+
// Correct
37+
import { A, B } from 'module';
38+
```
39+
40+
```ts
41+
// Correct
42+
import { A } from 'moduleA';
43+
import type { B } from 'moduleA';
44+
```

packages/tsl-module/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "tsl-module",
3+
"version": "0.1.3",
4+
"description": "A TSL plugin for JavaScript and TypeScript module syntax linting and transformations.",
5+
"keywords": [
6+
"tsl",
7+
"tsl-module"
8+
],
9+
"license": "MIT",
10+
"author": "Rel1cx<let@ik.me>",
11+
"sideEffects": false,
12+
"type": "module",
13+
"exports": {
14+
".": {
15+
"types": "./dist/index.d.ts",
16+
"import": "./dist/index.js"
17+
},
18+
"./package.json": "./package.json"
19+
},
20+
"files": [
21+
"dist",
22+
"./package.json"
23+
],
24+
"scripts": {
25+
"build": "tsdown --dts-resolve",
26+
"build:docs": "typedoc",
27+
"lint:publish": "pnpm publint",
28+
"lint:ts": "tsl",
29+
"publish": "pnpm run build && pnpm run lint:publish",
30+
"test": "vitest"
31+
},
32+
"dependencies": {
33+
"@let/eff": "jsr:^0.1.2",
34+
"ts-pattern": "^5.9.0"
35+
},
36+
"devDependencies": {
37+
"@local/configs": "workspace:*",
38+
"dedent": "^1.7.1",
39+
"tsdown": "^0.19.0-beta.2",
40+
"vitest": "^4.0.16"
41+
},
42+
"peerDependencies": {
43+
"tsl": "^1.0.28",
44+
"typescript": "^4.9.5 || ^5.4.5"
45+
},
46+
"engines": {
47+
"bun": ">=1.2.18",
48+
"node": ">=24.6.0"
49+
},
50+
"publishConfig": {
51+
"access": "public"
52+
}
53+
}

packages/tsl-module/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { noDuplicateImport } from "./rules/no-duplicate-import";
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import tsx from "dedent";
2+
import { ruleTester } from "tsl/ruleTester";
3+
import { expect, test } from "vitest";
4+
5+
import { messages, noDuplicateImport } from "./no-duplicate-import.js";
6+
7+
test("no-duplicate-import", () => {
8+
const ret = ruleTester({
9+
invalid: [
10+
{
11+
code: tsx`
12+
import { A } from 'module';
13+
import { B } from 'module';
14+
`,
15+
errors: [
16+
{
17+
line: 2,
18+
message: messages.noDuplicateImport({ source: "'module'" }),
19+
},
20+
],
21+
},
22+
{
23+
code: tsx`
24+
import type { A } from 'module';
25+
import type { B } from 'module';
26+
`,
27+
errors: [
28+
{
29+
line: 2,
30+
message: messages.noDuplicateImport({ source: "'module'" }),
31+
},
32+
],
33+
},
34+
{
35+
code: tsx`
36+
import defer { foo } from 'module';
37+
import defer { foo } from 'module';
38+
`,
39+
errors: [
40+
{
41+
line: 2,
42+
message: messages.noDuplicateImport({ source: "'module'" }),
43+
},
44+
],
45+
},
46+
],
47+
ruleFn: noDuplicateImport,
48+
tsx: true,
49+
valid: [
50+
tsx`
51+
import { A } from 'module1';
52+
import { A } from 'module2';
53+
import { A } from 'module3';
54+
`,
55+
tsx`
56+
import { A } from 'module';
57+
import type { A } from 'module';
58+
import defer { A } from 'module';
59+
`,
60+
],
61+
});
62+
expect(ret).toBe(false);
63+
});

0 commit comments

Comments
 (0)