Skip to content

Commit 0721606

Browse files
chore: updated eslint.config.mjs
1 parent f3d44c8 commit 0721606

24 files changed

Lines changed: 172 additions & 101 deletions

.vscode/settings.json

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
3-
"files.exclude": {
4-
"out": false // set this to true to hide the "out" folder with the compiled JS files
5-
},
6-
"search.exclude": {
7-
"out": true // set this to false to include "out" folder in search results
8-
},
9-
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off",
11-
"cssModulesIntellisense.aliases": {
12-
"~": "./src"
13-
},
14-
"cSpell.words": ["onig", "ovsx", "pcss", "styl", "vsctm"]
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off",
11+
"cssModulesIntellisense.aliases": {
12+
"~": "./src"
13+
},
14+
"cSpell.words": [
15+
"garg",
16+
"lokesh",
17+
"onig",
18+
"ovsx",
19+
"pcss",
20+
"styl",
21+
"vscodeignore",
22+
"vsctm"
23+
]
1524
}

docs/PROJECT_STRUCTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CSS/SCSS Modules IntelliSense VS Code extension.
55

66
## Directory Structure
77

8-
```
8+
```txt
99
css-modules-intellisense/
1010
├── .github/ # GitHub-specific files
1111
│ └── workflows/ # GitHub Actions workflows

eslint.config.mjs

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,78 @@
11
import typescriptEslint from "@typescript-eslint/eslint-plugin";
22
import tsParser from "@typescript-eslint/parser";
33

4-
export default [{
5-
files: ["**/*.ts"],
6-
}, {
4+
export default [
5+
{
6+
ignores: ["dist/**", "node_modules/**", "assets/**", ".vscode-test/**"],
7+
},
8+
{
9+
files: ["src/**/*.ts"],
710
plugins: {
8-
"@typescript-eslint": typescriptEslint,
11+
"@typescript-eslint": typescriptEslint,
912
},
10-
1113
languageOptions: {
12-
parser: tsParser,
13-
ecmaVersion: 2022,
14-
sourceType: "module",
14+
parser: tsParser,
15+
ecmaVersion: 2022,
16+
sourceType: "module",
17+
parserOptions: {
18+
project: true,
19+
tsconfigRootDir: import.meta.dirname,
20+
},
1521
},
16-
1722
rules: {
18-
"@typescript-eslint/naming-convention": ["warn", {
19-
selector: "import",
20-
format: ["camelCase", "PascalCase"],
21-
}],
23+
// Naming
24+
"@typescript-eslint/naming-convention": [
25+
"warn",
26+
{ selector: "import", format: ["camelCase", "PascalCase"] },
27+
],
28+
29+
// Correctness
30+
curly: "warn",
31+
eqeqeq: ["warn", "always"],
32+
"@typescript-eslint/only-throw-error": "warn",
33+
"@typescript-eslint/no-floating-promises": "error",
34+
"@typescript-eslint/no-misused-promises": "error",
35+
"@typescript-eslint/await-thenable": "error",
2236

23-
curly: "warn",
24-
eqeqeq: "warn",
25-
"no-throw-literal": "warn",
26-
semi: "warn",
37+
// Type safety
38+
"@typescript-eslint/no-explicit-any": "warn",
39+
"@typescript-eslint/no-unsafe-assignment": "warn",
40+
"@typescript-eslint/no-unsafe-member-access": "warn",
41+
"@typescript-eslint/no-unsafe-call": "warn",
42+
"@typescript-eslint/no-unsafe-return": "warn",
43+
44+
// Dead code
45+
"@typescript-eslint/no-unused-vars": [
46+
"warn",
47+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
48+
],
49+
"no-unused-vars": "off", // disabled in favour of @typescript-eslint/no-unused-vars
50+
51+
// Code style
52+
semi: "warn",
53+
"@typescript-eslint/consistent-type-imports": [
54+
"warn",
55+
{ prefer: "type-imports", fixStyle: "inline-type-imports" },
56+
],
57+
"@typescript-eslint/prefer-nullish-coalescing": "warn",
58+
"@typescript-eslint/prefer-optional-chain": "warn",
59+
},
60+
},
61+
{
62+
// Looser rules for config/test files — no type-aware linting needed
63+
files: ["*.mjs", "src/test/**/*.ts"],
64+
plugins: {
65+
"@typescript-eslint": typescriptEslint,
66+
},
67+
languageOptions: {
68+
parser: tsParser,
69+
ecmaVersion: 2022,
70+
sourceType: "module",
71+
},
72+
rules: {
73+
curly: "warn",
74+
eqeqeq: "warn",
75+
semi: "warn",
2776
},
28-
}];
77+
},
78+
];

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export async function activate(context: vscode.ExtensionContext) {
2121
CheckDocument.diagnosticCollection = diagnosticCollection;
2222

2323
Cache.context = context;
24-
const loaded = Cache.loadCache();
24+
const loaded = await Cache.loadCache();
2525
if (!loaded) {
26-
CssModuleDependencyCache.populateCacheFromWorkspace();
26+
await CssModuleDependencyCache.populateCacheFromWorkspace();
2727
}
2828
loadCaches();
2929

src/libs/cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from "fs";
22
import * as path from "path";
3-
import * as vscode from "vscode";
3+
import type * as vscode from "vscode";
44
import { CSS_MODULES_CACHE_FILENAME, DEBOUNCE_TIMER } from "../config";
55
import {
6-
CacheJsonObject,
6+
type CacheJsonObject,
77
ClassNameCache,
88
ClassNameRangeMap,
99
ModulePathCache,
@@ -79,7 +79,7 @@ export default class Cache {
7979
static async saveCache() {
8080
clearTimeout(this.saveCacheDebounceId);
8181
this.saveCacheDebounceId = setTimeout(() => {
82-
this._saveCache();
82+
this._saveCache().catch(console.error);
8383
}, DEBOUNCE_TIMER.CACHE);
8484
}
8585

@@ -142,10 +142,10 @@ export default class Cache {
142142
const parsed: { [K in keyof CacheJsonObject]?: CacheJsonObject[K] } =
143143
JSON.parse(raw);
144144

145-
this.pathMapCache.setArray(parsed.pathMapCache || []);
145+
this.pathMapCache.setArray(parsed.pathMapCache ?? []);
146146

147147
this.modulePathCache.setMap(
148-
Object.entries(parsed.modulePathCache || {}).map(
148+
Object.entries(parsed.modulePathCache ?? {}).map(
149149
([key, valueArray]) => [
150150
key,
151151
new ModulePathCacheSet(this.pathMapCache, valueArray),
@@ -154,7 +154,7 @@ export default class Cache {
154154
);
155155

156156
this.classNameCache.setMap(
157-
Object.entries(parsed.classNameCache || {}).map(([key, value]) => [
157+
Object.entries(parsed.classNameCache ?? {}).map(([key, value]) => [
158158
key,
159159
new ClassNameRangeMap(Object.entries(value)),
160160
])

src/libs/checkDocument.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class CheckDocument {
6060
static push(document: vscode.TextDocument): number {
6161
if (this.isQueueEmpty()) {
6262
const length = this.documentQueue.push(document);
63-
this.checkNextDocument();
63+
this.checkNextDocument().catch(console.error);
6464
return length;
6565
}
6666
while (this.documentQueue.length >= MAX_CHECK_DOCUMENT_QUEUE_LENGTH) {
@@ -109,7 +109,7 @@ export default class CheckDocument {
109109
static setDebounceTimer(): void {
110110
clearTimeout(this.debounceTimerId);
111111
this.debounceTimerId = setTimeout(() => {
112-
this.checkNextDocument();
112+
this.checkNextDocument().catch(console.error);
113113
}, DEBOUNCE_TIMER.CHECK_DOCUMENT);
114114
}
115115

@@ -137,7 +137,6 @@ export default class CheckDocument {
137137
return;
138138
}
139139

140-
const text = document.getText();
141140
const diagnostics: vscode.Diagnostic[] = [];
142141
const importMatches = await getAllImportModulePaths(document);
143142

src/libs/classNameCache.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { sanitizeCssInput } from "../utils/sanitizeCssInput";
1212
import isPositionInComment from "../utils/isPositionInComment";
1313
import CssModuleDependencyCache from "./cssModuleDependencyCache";
1414
import CheckDocument from "./checkDocument";
15-
import { ClassNameRange, ClassNameRangeMap } from "../types/cache";
15+
import { type ClassNameRange, ClassNameRangeMap } from "../types/cache";
1616

1717
/**
1818
* A utility class to extract and cache class names from CSS Module files.
@@ -34,23 +34,25 @@ export default class ClassNameCache {
3434
static async updateClassNameCache(e: vscode.TextDocument) {
3535
const importPath = getWorkspaceRelativeUriPath(e.uri);
3636
clearTimeout(this.ClassNameCacheDebounceIdMap[importPath]);
37-
this.ClassNameCacheDebounceIdMap[importPath] = setTimeout(async () => {
38-
await ClassNameCache.extractFromUri(e.uri);
37+
this.ClassNameCacheDebounceIdMap[importPath] = setTimeout(() => {
38+
(async () => {
39+
await ClassNameCache.extractFromUri(e.uri);
3940

40-
if (SUPPORTED_MODULES.includes(e.languageId)) {
41-
const dependents = CssModuleDependencyCache.getDependentsForDocument(e);
41+
if (SUPPORTED_MODULES.includes(e.languageId)) {
42+
const dependents =
43+
CssModuleDependencyCache.getDependentsForDocument(e);
4244

43-
for (const workspacePath of dependents) {
44-
const resolvedPath = resolveWorkspaceRelativePath(workspacePath);
45-
if (!resolvedPath) {
46-
continue;
45+
for (const workspacePath of dependents) {
46+
const resolvedPath = resolveWorkspaceRelativePath(workspacePath);
47+
if (!resolvedPath) {
48+
continue;
49+
}
50+
const document =
51+
await vscode.workspace.openTextDocument(resolvedPath);
52+
CheckDocument.push(document);
4753
}
48-
const document = await vscode.workspace.openTextDocument(
49-
resolvedPath
50-
);
51-
CheckDocument.push(document);
5254
}
53-
}
55+
})().catch(console.error);
5456
}, DEBOUNCE_TIMER.UPDATE_CLASS_NAME);
5557
}
5658

@@ -182,11 +184,11 @@ export default class ClassNameCache {
182184
): Promise<string[] | undefined> {
183185
if (Cache.classNameCache.hasByKey(importPath)) {
184186
return Array.from(
185-
Cache.classNameCache.getByKey(importPath)?.keys() || []
187+
Cache.classNameCache.getByKey(importPath)?.keys() ?? []
186188
);
187189
} else {
188190
return Array.from(
189-
(await this.extractAndCacheClassNames(importPath))?.keys() || []
191+
(await this.extractAndCacheClassNames(importPath))?.keys() ?? []
190192
);
191193
}
192194
}
@@ -279,7 +281,7 @@ export default class ClassNameCache {
279281
}
280282

281283
Cache.classNameCache.setByKey(importPath, classNames);
282-
Cache.saveCache();
284+
Cache.saveCache().catch(console.error);
283285
return classNames;
284286
}
285287
}

src/libs/cssModuleDependencyCache.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class CssModuleDependencyCache {
2121
await this.updateCacheForDocument({ uri });
2222
}
2323

24-
Cache.saveCache();
24+
Cache.saveCache().catch(console.error);
2525
}
2626

2727
/**
@@ -66,13 +66,11 @@ export default class CssModuleDependencyCache {
6666
const sourceFile = getWorkspaceRelativeUriPath(document.uri);
6767

6868
let dependents = Cache.modulePathCache.getByKey(relativeImport);
69-
if (!dependents) {
70-
dependents = Cache.modulePathCache.createKey(relativeImport);
71-
}
69+
dependents ??= Cache.modulePathCache.createKey(relativeImport);
7270
dependents.addByKey(sourceFile);
7371
}
7472

75-
Cache.saveCache();
73+
Cache.saveCache().catch(console.error);
7674
}
7775

7876
/**
@@ -84,7 +82,7 @@ export default class CssModuleDependencyCache {
8482
return (
8583
Cache.modulePathCache
8684
.getByKey(getWorkspaceRelativeUriPath(document.uri))
87-
?.toKeyArray() || []
85+
?.toKeyArray() ?? []
8886
);
8987
}
9088

src/libs/loadCaches.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,52 @@ import { registerTriggerOnEdit, registerTriggerOnSave } from "./processConfig";
55

66
const loadCaches = () => {
77
// ClassNameCache
8-
registerTriggerOnSave((e) => ClassNameCache.updateClassNameCache(e));
8+
registerTriggerOnSave((e) => {
9+
ClassNameCache.updateClassNameCache(e).catch(console.error);
10+
});
911

10-
registerTriggerOnEdit((e) => ClassNameCache.updateClassNameCache(e.document));
12+
registerTriggerOnEdit((e) => {
13+
ClassNameCache.updateClassNameCache(e.document).catch(console.error);
14+
});
1115

12-
vscode.workspace.onDidDeleteFiles((e) =>
13-
e.files.forEach((uri) => ClassNameCache.extractFromUri(uri))
14-
);
16+
vscode.workspace.onDidDeleteFiles((e) => {
17+
e.files.forEach((uri) => {
18+
ClassNameCache.extractFromUri(uri).catch(console.error);
19+
});
20+
});
1521

1622
// CssModuleDependencyCache
1723
vscode.workspace.onDidCreateFiles((e) => {
1824
for (const uri of e.files) {
19-
CssModuleDependencyCache.updateCacheForDocument({ uri });
25+
CssModuleDependencyCache.updateCacheForDocument({ uri }).catch(
26+
console.error
27+
);
2028
}
2129
});
2230

23-
registerTriggerOnSave((e) =>
24-
CssModuleDependencyCache.updateCacheForDocument({ document: e })
25-
);
31+
registerTriggerOnSave((e) => {
32+
CssModuleDependencyCache.updateCacheForDocument({ document: e }).catch(
33+
console.error
34+
);
35+
});
2636

27-
vscode.workspace.onDidOpenTextDocument((e) =>
28-
CssModuleDependencyCache.updateCacheForDocument({ document: e })
29-
);
37+
vscode.workspace.onDidOpenTextDocument((e) => {
38+
CssModuleDependencyCache.updateCacheForDocument({ document: e }).catch(
39+
console.error
40+
);
41+
});
3042

31-
registerTriggerOnEdit((e) =>
32-
CssModuleDependencyCache.updateCacheForDocument({ document: e.document })
33-
);
43+
registerTriggerOnEdit((e) => {
44+
CssModuleDependencyCache.updateCacheForDocument({
45+
document: e.document,
46+
}).catch(console.error);
47+
});
3448

3549
const files = vscode.workspace.textDocuments;
3650
for (const file of files) {
37-
CssModuleDependencyCache.updateCacheForDocument({ document: file });
51+
CssModuleDependencyCache.updateCacheForDocument({ document: file }).catch(
52+
console.error
53+
);
3854
}
3955
};
4056

0 commit comments

Comments
 (0)