@travetto/lint 8.0.0-alpha.20

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 ADDED
@@ -0,0 +1,87 @@
1
+ <!-- This file was generated by @travetto/doc and should not be modified directly -->
2
+ <!-- Please modify https://github.com/travetto/travetto/tree/main/module/lint/DOC.tsx and execute "npx trv doc" to rebuild -->
3
+ # Lint Support
4
+
5
+ ## Linting and Formatting integration for Travetto
6
+
7
+ **Install: @travetto/lint**
8
+ ```bash
9
+ npm install @travetto/lint
10
+
11
+ # or
12
+
13
+ yarn add @travetto/lint
14
+ ```
15
+
16
+ [Biome](https://biomejs.dev/) is the tool used for linting, formatting, and organizing imports in [Typescript](https://typescriptlang.org) and [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) code. This module provides a unified CLI interface and standard linting patterns. In a new project, the first thing that will need to be done, post installation, is to create the Biome configuration file.
17
+
18
+ ## CLI - lint:register
19
+
20
+ **Terminal: Help for lint:register**
21
+ ```bash
22
+ $ trv lint:register --help
23
+
24
+ Usage: lint:register [options]
25
+
26
+ Description:
27
+ Generate the workspace Biome configuration entry file.
28
+
29
+ This bootstraps `biome.jsonc` to extend the framework-provided rules configuration.
30
+
31
+ Options:
32
+ --help display help for command
33
+ ```
34
+
35
+ When registration completes, this is the file the linter will use, and any other tooling (e.g. IDEs).
36
+
37
+ **Code: Sample configuration**
38
+ ```json
39
+ {
40
+ "$schema": "https://biomejs.dev/schemas/2.5.4/schema.json",
41
+ "extends": ["./node_modules/@travetto/lint/resources/biome.jsonc"],
42
+ "files": {
43
+ "includes": [
44
+ "**",
45
+ "!**/out",
46
+ "!**/ui",
47
+ "!**/api-client",
48
+ "!**/*.d.ts",
49
+ "!**/fixtures",
50
+ "!**/resources",
51
+ "!**/DOC.html",
52
+ "!**/README.md",
53
+ "!archived/**",
54
+ "!related/travetto.github.io/**"
55
+ ]
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## CLI - lint
61
+ Once registered, using the linter is as simple as invoking it via the cli:
62
+
63
+ **Terminal: Running the Linter**
64
+ ```bash
65
+ npx trv lint
66
+ ```
67
+
68
+ Or pointing your IDE to reference the registered configuration file.
69
+
70
+ **Terminal: Help for lint**
71
+ ```bash
72
+ $ trv lint --help
73
+
74
+ Usage: lint [options]
75
+
76
+ Description:
77
+ Run Biome linter/formatter for the workspace or changed files.
78
+
79
+ Supports incremental mode (`changed`/`since`) and forwards format/fix
80
+ options to the underlying biome invocation.
81
+
82
+ Options:
83
+ -c, --changed Only check changed modules (default: false)
84
+ -s, --since <string> Since a specific git commit
85
+ -f, --fix Should we attempt to fix/write formatting changes?
86
+ --help display help for command
87
+ ```
package/__index__.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Empty index file for @travetto/lint
2
+ export {};
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@travetto/lint",
3
+ "version": "8.0.0-alpha.20",
4
+ "type": "module",
5
+ "description": "Linting and Formatting integration for Travetto",
6
+ "keywords": [
7
+ "lint",
8
+ "travetto",
9
+ "typescript",
10
+ "biome"
11
+ ],
12
+ "homepage": "https://travetto.io",
13
+ "license": "MIT",
14
+ "author": {
15
+ "email": "travetto.framework@gmail.com",
16
+ "name": "Travetto Framework"
17
+ },
18
+ "main": "__index__.ts",
19
+ "files": [
20
+ "support",
21
+ "__index__.ts",
22
+ "resources"
23
+ ],
24
+ "repository": {
25
+ "url": "git+https://github.com/travetto/travetto.git",
26
+ "directory": "module/lint"
27
+ },
28
+ "dependencies": {
29
+ "@travetto/runtime": "^8.0.0-alpha.20",
30
+ "@biomejs/biome": "^2.5.3"
31
+ },
32
+ "peerDependencies": {
33
+ "@travetto/cli": "^8.0.0-alpha.28"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@travetto/cli": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "travetto": {
41
+ "displayName": "Lint Support"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }
@@ -0,0 +1,145 @@
1
+ {
2
+ "root": false,
3
+ "$schema": "https://biomejs.dev/schemas/2.5.4/schema.json",
4
+ "vcs": {
5
+ "enabled": true,
6
+ "clientKind": "git",
7
+ "useIgnoreFile": true
8
+ },
9
+ "files": {
10
+ "ignoreUnknown": true,
11
+ "includes": [
12
+ "**",
13
+ "!**/*.d.ts",
14
+ "!**/fixtures",
15
+ "!**/resources",
16
+ "!**/DOC.html",
17
+ "!**/.vscode",
18
+ ]
19
+ },
20
+ "formatter": {
21
+ "enabled": true,
22
+ "formatWithErrors": false,
23
+ "indentStyle": "space",
24
+ "indentWidth": 2,
25
+ "lineWidth": 140,
26
+ },
27
+ "assist": {
28
+ "actions": {
29
+ "source": {
30
+ "organizeImports": {
31
+ "level": "on",
32
+ "options": {
33
+ "groups": [
34
+ [
35
+ ":NODE:",
36
+ ":BUN:"
37
+ ],
38
+ ":BLANK_LINE:",
39
+ [
40
+ ":PACKAGE:",
41
+ "!@travetto/**"
42
+ ],
43
+ ":BLANK_LINE:",
44
+ "@travetto/*",
45
+ ":BLANK_LINE:",
46
+ "@travetto/**/*.ts",
47
+ ":BLANK_LINE:",
48
+ [
49
+ ":ALIAS:",
50
+ ":PATH:"
51
+ ]
52
+ ]
53
+ }
54
+ }
55
+ }
56
+ }
57
+ },
58
+ "linter": {
59
+ "enabled": true,
60
+ "rules": {
61
+ "preset": "recommended",
62
+ "style": {
63
+ "useImportType": "error",
64
+ "noNonNullAssertion": "off",
65
+ "useConst": "error",
66
+ },
67
+ "correctness": {
68
+ "noUnusedFunctionParameters": "off",
69
+ "noUnusedPrivateClassMembers": "off",
70
+ "noUnusedVariables": {
71
+ "level": "on",
72
+ "options": {
73
+ "ignore": {
74
+ "class": [
75
+ "*"
76
+ ],
77
+ "typeParameter": [
78
+ "*"
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "complexity": {
85
+ "useArrowFunction": "off",
86
+ "noStaticOnlyClass": "off",
87
+ "noThisInStatic": "off",
88
+ "noBannedTypes": "off",
89
+ },
90
+ "suspicious": {
91
+ "noVar": "error",
92
+ "noTsIgnore": "off",
93
+ "noConfusingVoidType": "off",
94
+ "noEmptyInterface": "off",
95
+ "noAssignInExpressions": "off"
96
+ }
97
+ }
98
+ },
99
+ "javascript": {
100
+ "formatter": {
101
+ "quoteStyle": "single",
102
+ "semicolons": "always",
103
+ "arrowParentheses": "asNeeded",
104
+ "trailingCommas": "none"
105
+ },
106
+ "parser": {
107
+ "unsafeParameterDecoratorsEnabled": true
108
+ }
109
+ },
110
+ "json": {
111
+ "formatter": {
112
+ "lineWidth": 80
113
+ }
114
+ },
115
+ "overrides": [
116
+ {
117
+ "includes": [
118
+ "**/test/**",
119
+ "**/support/test/**",
120
+ "**/doc/**",
121
+ "!module/test/src/**"
122
+ ],
123
+ "linter": {
124
+ "rules": {
125
+ "complexity": {
126
+ "noUselessConstructor": "off"
127
+ },
128
+ "correctness": {
129
+ "noUnusedVariables": "off",
130
+ "noUnusedFunctionParameters": "off",
131
+ },
132
+ "security": {
133
+ "noBlankTarget": "off"
134
+ },
135
+ "style": {
136
+ "useConst": "off"
137
+ },
138
+ "suspicious": {
139
+ "noSelfCompare": "off"
140
+ }
141
+ }
142
+ }
143
+ }
144
+ ]
145
+ }
@@ -0,0 +1,55 @@
1
+ import { spawn } from 'node:child_process';
2
+
3
+ import { CliCommand, type CliCommandShape, CliModuleUtil, CliParseUtil } from '@travetto/cli';
4
+ import { Env, ExecUtil, Runtime } from '@travetto/runtime';
5
+
6
+ /**
7
+ * Run Biome linter/formatter for the workspace or changed files.
8
+ *
9
+ * Supports incremental mode (`changed`/`since`) and forwards format/fix
10
+ * options to the underlying biome invocation.
11
+ */
12
+ @CliCommand()
13
+ export class LintCommand implements CliCommandShape {
14
+ /** Only check changed modules */
15
+ changed = false;
16
+
17
+ /** Since a specific git commit */
18
+ since?: string;
19
+
20
+ /** Should we attempt to fix/write formatting changes? */
21
+ fix?: boolean;
22
+
23
+ finalize(): void {
24
+ Env.DEBUG.set(false);
25
+ }
26
+
27
+ async main(): Promise<void> {
28
+ const paths = await CliModuleUtil.findChangedPaths({ changed: this.changed, since: this.since, logError: true });
29
+
30
+ if ((this.changed || this.since) && paths.length === 0) {
31
+ console.log('No changed files found to lint.');
32
+ return;
33
+ }
34
+
35
+ const state = CliParseUtil.getState(this);
36
+ const result = await ExecUtil.getResult(
37
+ spawn(
38
+ process.argv0,
39
+ [
40
+ Runtime.workspaceRelative('node_modules', '.bin', 'biome'),
41
+ 'check',
42
+ ...(this.fix ? ['--write'] : []),
43
+ ...paths,
44
+ ...(state?.unknown ?? [])
45
+ ],
46
+ {
47
+ stdio: 'inherit'
48
+ }
49
+ ),
50
+ { catch: true }
51
+ );
52
+
53
+ process.exitCode = result.code;
54
+ }
55
+ }
@@ -0,0 +1,27 @@
1
+ import fs from 'node:fs/promises';
2
+
3
+ import { CliCommand, type CliCommandShape } from '@travetto/cli';
4
+ import { Runtime } from '@travetto/runtime';
5
+
6
+ /**
7
+ * Generate the workspace Biome configuration entry file.
8
+ *
9
+ * This bootstraps `biome.jsonc` to extend the framework-provided rules configuration.
10
+ */
11
+ @CliCommand({})
12
+ export class LintRegisterCommand implements CliCommandShape {
13
+ async main(): Promise<void> {
14
+ const content = `{
15
+ "$schema": "https://biomejs.dev/schemas/2.5.4/schema.json",
16
+ "extends": ["./node_modules/@travetto/lint/resources/biome.jsonc"]
17
+ }
18
+ `;
19
+ const output = Runtime.workspaceRelative('biome.jsonc');
20
+ if (!(await fs.stat(output, { throwIfNoEntry: false }))) {
21
+ await fs.writeFile(output, content);
22
+ console.log(`Wrote lint config to ${output}`);
23
+ } else {
24
+ console.log(`Lint config already present ${output}`);
25
+ }
26
+ }
27
+ }