Skip to content

Commit e37a723

Browse files
authored
chore: New linting setup. (#579)
This PR enables a number of lint rules + fixes up the violations.
1 parent fc3b773 commit e37a723

24 files changed

Lines changed: 258 additions & 134 deletions

docs/.vitepress/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ export default extendConfig(
718718
provider: 'local',
719719
},
720720
},
721-
transformHead({ page, pageData, assets }) {
721+
transformHead({ page, pageData }) {
722722
// Remove .md suffix and replace index with empty string (to cover index.md)
723723
const url = 'https://viteplus.dev/' + page.replace(/\.md$/, '').replace(/index$/, '');
724724

docs/.vitepress/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Vue SFC module declaration
22
declare module '*.vue' {
33
import type { DefineComponent } from 'vue';
4-
const component: DefineComponent<{}, {}, any>;
4+
const component: DefineComponent<{}, {}, unknown>;
55
export default component;
66
}
77

docs/.vitepress/theme/components/home/FeatureToolbar.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const scrollToSection = (e: Event, id: string) => {
2121
e.stopPropagation();
2222
2323
const element = document.getElementById(id);
24-
if (!element) return;
24+
if (!element) {
25+
return;
26+
}
2527
2628
// Get the toolbar height to offset the scroll
2729
const toolbar = (e.currentTarget as HTMLElement).closest('section');
@@ -38,7 +40,9 @@ const scrollToSection = (e: Event, id: string) => {
3840
let startTime: number | null = null;
3941
4042
const animation = (currentTime: number) => {
41-
if (startTime === null) startTime = currentTime;
43+
if (startTime === null) {
44+
startTime = currentTime;
45+
}
4246
const timeElapsed = currentTime - startTime;
4347
const progress = Math.min(timeElapsed / duration, 1);
4448
@@ -89,7 +93,9 @@ const determineActiveSection = () => {
8993
const sections = features
9094
.map((feature) => {
9195
const element = document.getElementById(feature.id);
92-
if (!element) return null;
96+
if (!element) {
97+
return null;
98+
}
9399
94100
const rect = element.getBoundingClientRect();
95101
return {
@@ -107,7 +113,9 @@ const determineActiveSection = () => {
107113
let activeId = activeSection.value;
108114
109115
for (const section of sections) {
110-
if (!section) continue;
116+
if (!section) {
117+
continue;
118+
}
111119
112120
// If section top is near or above threshold and bottom is below threshold
113121
if (section.top <= threshold && section.bottom > threshold) {

docs/.vitepress/theme/components/home/Hero.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ const smoothScrollTo = (e: Event, targetId: string) => {
4949
e.stopPropagation();
5050
5151
const element = document.getElementById(targetId);
52-
if (!element) return;
52+
if (!element) {
53+
return;
54+
}
5355
5456
const elementPosition = element.getBoundingClientRect().top + window.scrollY;
5557
const offsetPosition = elementPosition;
@@ -61,7 +63,9 @@ const smoothScrollTo = (e: Event, targetId: string) => {
6163
let startTime: number | null = null;
6264
6365
const animation = (currentTime: number) => {
64-
if (startTime === null) startTime = currentTime;
66+
if (startTime === null) {
67+
startTime = currentTime;
68+
}
6569
const timeElapsed = currentTime - startTime;
6670
const progress = Math.min(timeElapsed / duration, 1);
6771

docs/.vitepress/theme/components/home/Terminal.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const goToNextTab = () => {
3232
3333
// Handle animation completion
3434
const onAnimationComplete = () => {
35-
if (!autoPlayEnabled.value) return;
35+
if (!autoPlayEnabled.value) {
36+
return;
37+
}
3638
3739
// Clear any existing timeout
3840
if (autoAdvanceTimeout) {
@@ -59,7 +61,9 @@ const onTabChange = () => {
5961
6062
// Setup Intersection Observer
6163
onMounted(() => {
62-
if (!sectionRef.value) return;
64+
if (!sectionRef.value) {
65+
return;
66+
}
6367
6468
observer = new IntersectionObserver(
6569
(entries) => {

packages/cli/build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ async function syncCorePackageExports() {
237237
const srcPath = join(coreClientDir, file);
238238
const shimPath = join(clientDir, file);
239239
// Skip directories
240-
if (statSync(srcPath).isDirectory()) continue;
240+
if (statSync(srcPath).isDirectory()) {
241+
continue;
242+
}
241243
if (file.endsWith('.js') || file.endsWith('.mjs') || file.endsWith('.cjs')) {
242244
await writeFile(shimPath, `export * from '${CORE_PACKAGE_NAME}/dist/client/${file}';\n`);
243245
} else if (file.endsWith('.d.ts') || file.endsWith('.d.mts') || file.endsWith('.d.cts')) {
@@ -288,7 +290,9 @@ async function syncTypesDir(srcDir: string, destDir: string, relativePath: strin
288290

289291
if (statSync(srcPath).isDirectory()) {
290292
// Skip top-level internal directory - it's blocked by ./types/internal/* export
291-
if (entry === 'internal' && relativePath === '') continue;
293+
if (entry === 'internal' && relativePath === '') {
294+
continue;
295+
}
292296

293297
await mkdir(destPath, { recursive: true });
294298
await syncTypesDir(srcPath, destPath, entryRelPath);

packages/cli/src/oxlint-config.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ function jsToJSONProps(typ: any): any {
572572

573573
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
574574
function transformPrimitive(typ: string, val: any): any {
575-
if (typeof typ === typeof val) return val;
575+
if (typeof typ === typeof val) {
576+
return val;
577+
}
576578
return invalidValue(typ, val, key, parent);
577579
}
578580

@@ -589,7 +591,9 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any
589591
}
590592

591593
function transformEnum(cases: string[], val: any): any {
592-
if (cases.indexOf(val) !== -1) return val;
594+
if (cases.indexOf(val) !== -1) {
595+
return val;
596+
}
593597
return invalidValue(
594598
cases.map((a) => {
595599
return l(a);
@@ -602,7 +606,9 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any
602606

603607
function transformArray(typ: any, val: any): any {
604608
// val must be an array with no invalid elements
605-
if (!Array.isArray(val)) return invalidValue(l('array'), val, key, parent);
609+
if (!Array.isArray(val)) {
610+
return invalidValue(l('array'), val, key, parent);
611+
}
606612
return val.map((el) => transform(el, typ, getProps));
607613
}
608614

@@ -635,18 +641,26 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any
635641
return result;
636642
}
637643

638-
if (typ === 'any') return val;
644+
if (typ === 'any') {
645+
return val;
646+
}
639647
if (typ === null) {
640-
if (val === null) return val;
648+
if (val === null) {
649+
return val;
650+
}
651+
return invalidValue(typ, val, key, parent);
652+
}
653+
if (typ === false) {
641654
return invalidValue(typ, val, key, parent);
642655
}
643-
if (typ === false) return invalidValue(typ, val, key, parent);
644656
let ref: any = undefined;
645657
while (typeof typ === 'object' && typ.ref !== undefined) {
646658
ref = typ.ref;
647659
typ = typeMap[typ.ref];
648660
}
649-
if (Array.isArray(typ)) return transformEnum(typ, val);
661+
if (Array.isArray(typ)) {
662+
return transformEnum(typ, val);
663+
}
650664
if (typeof typ === 'object') {
651665
return typ.hasOwnProperty('unionMembers')
652666
? transformUnion(typ.unionMembers, val)
@@ -657,7 +671,9 @@ function transform(val: any, typ: any, getProps: any, key: any = '', parent: any
657671
: invalidValue(typ, val, key, parent);
658672
}
659673
// Numbers can be parsed by Date but shouldn't be.
660-
if (typ === Date && typeof val !== 'number') return transformDate(val);
674+
if (typ === Date && typeof val !== 'number') {
675+
return transformDate(val);
676+
}
661677
return transformPrimitive(typ, val);
662678
}
663679

packages/cli/src/pack-bin.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ cli
7575
.option('-F, --filter <pattern>', 'Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name')
7676
.option('--exports', 'Generate export-related metadata for package.json (experimental)')
7777
.action(async (input: string[], flags: InlineConfig) => {
78-
if (input.length > 0) flags.entry = input;
78+
if (input.length > 0) {
79+
flags.entry = input;
80+
}
7981
if (flags.envPrefix === undefined) {
8082
flags.envPrefix = DEFAULT_ENV_PREFIXES;
8183
}
@@ -84,7 +86,9 @@ cli
8486
const viteConfig = await resolveConfig({ root: process.cwd() }, 'build');
8587

8688
const configFiles: string[] = [];
87-
if (viteConfig.configFile) configFiles.push(viteConfig.configFile);
89+
if (viteConfig.configFile) {
90+
configFiles.push(viteConfig.configFile);
91+
}
8892

8993
const configs: ResolvedConfig[] = [];
9094
const packConfigs = Array.isArray(viteConfig.pack)
@@ -108,8 +112,8 @@ export async function runCLI(): Promise<void> {
108112

109113
try {
110114
await cli.runMatchedCommand();
111-
} catch (error: any) {
112-
globalLogger.error(String(error.stack || error.message));
115+
} catch (error) {
116+
globalLogger.error(error instanceof Error ? error.stack || error.message : error);
113117
process.exit(1);
114118
}
115119
}

packages/core/build-support/rewrite-module-specifiers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ function getQuoteChar(node: SgNode): string {
5858
* Matches exact, subpath (from/...), or file extension (from.xxx)
5959
*/
6060
function matchesFrom(specifier: string, from: string): boolean {
61-
if (specifier === from) return true;
62-
if (!specifier.startsWith(from)) return false;
61+
if (specifier === from) {
62+
return true;
63+
}
64+
if (!specifier.startsWith(from)) {
65+
return false;
66+
}
6367
// Check the character after the prefix - must be '/', '.', or end of string
6468
const nextChar = specifier[from.length];
6569
return nextChar === '/' || nextChar === '.';

packages/core/build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ async function bundleVitepress() {
339339

340340
for (const file of vitepressDistFiles) {
341341
const stats = await stat(file);
342-
if (!stats.isFile()) continue;
342+
if (!stats.isFile()) {
343+
continue;
344+
}
343345

344346
// Normalize paths to use forward slashes for consistent replacement on Windows
345347
const relativePath = toPosixPath(file).replace(
@@ -392,7 +394,9 @@ async function bundleVitepress() {
392394

393395
for (const file of vitepressTypesFiles) {
394396
const stats = await stat(file);
395-
if (!stats.isFile()) continue;
397+
if (!stats.isFile()) {
398+
continue;
399+
}
396400

397401
// Normalize paths to use forward slashes for consistent replacement on Windows
398402
const relativePath = toPosixPath(file).replace(toPosixPath(vitepressTypesDir), '');

0 commit comments

Comments
 (0)