Skip to content

Commit 08d8de5

Browse files
committed
feat: add lint trim option
1 parent 8f93cdd commit 08d8de5

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/lint/file.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ export class LintFile {
411411
// private
412412
async #lint () {
413413
const configs = await this.#getConfigs( this.#cwd ),
414+
cliConfig = configs.cli
415+
? await this.#getCliConfig( configs.cli )
416+
: null,
414417
editorConfig = await this.#getEditorConfig( {
415418
"fallbackToDefault": configs.package
416419
? Boolean( configs.cli )
@@ -474,8 +477,10 @@ export class LintFile {
474477
// trim trailing whitespaces
475478
if ( editorConfig.trim_trailing_whitespace ) {
476479
this.#data = this.#data.replaceAll( new RegExp( ` +${ EOL[ eol ] }`, "g" ), EOL[ eol ] );
480+
}
477481

478-
// trim
482+
// trim
483+
if ( cliConfig?.lint.trim ) {
479484
this.#data = this.#data.trim();
480485
}
481486

@@ -1179,6 +1184,20 @@ export class LintFile {
11791184
}
11801185
}
11811186

1187+
async #getCliConfig ( path ) {
1188+
if ( !path ) return;
1189+
1190+
this.#cache.cliConfigs ||= new Map();
1191+
1192+
if ( !this.#cache.cliConfigs.has( path ) ) {
1193+
this.#cache.cliConfigs.set( path, null );
1194+
1195+
// XXX
1196+
}
1197+
1198+
return this.#cache.cliConfigs.get( path );
1199+
}
1200+
11821201
async #getEditorConfig ( { fallbackToDefault } = {} ) {
11831202
this.#cache.editorConfigs ||= new Map();
11841203

resources/cli.config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ meta:
4646
dependabotsecurityupdates: true
4747
privateVulnerabilityReporting: true
4848

49+
lint:
50+
trim: true
51+
4952
release:
5053
enabled: false
5154
branches: [main]

resources/schemas/cli.config.schema.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ properties:
102102
additionalProperties: false
103103
required: [dependabot, executables, repository]
104104

105+
lint:
106+
type: object
107+
properties:
108+
trim: { type: boolean }
109+
additionalProperties: false
110+
required: [trim]
111+
105112
subPackages:
106113
anyOf:
107114
- type: "null"
@@ -251,4 +258,4 @@ properties:
251258
required: [location]
252259

253260
additionalProperties: false
254-
required: [meta, release, commits]
261+
required: [meta, lint, release, commits]

0 commit comments

Comments
 (0)