Skip to content

Commit e850f1a

Browse files
committed
feat: add editorconfig trim option
1 parent 06af09c commit e850f1a

6 files changed

Lines changed: 19 additions & 36 deletions

File tree

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
max_line_length = off
10+
11+
max_line_length = unset
12+
trim = true
1113

1214
[*.{yaml,yml}]
1315
indent_size = 2

lib/lint/file.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Table from "#core/text/table";
1515
import * as utils from "#core/utils";
1616
import uuid from "#core/uuid";
1717
import Markdown from "#lib/markdown";
18-
import { getCliConfig } from "#lib/utils";
1918

2019
// NOTE: status codes:
2120
const STATUSES = {
@@ -412,7 +411,6 @@ export class LintFile {
412411
// private
413412
async #lint () {
414413
const configs = await this.#getConfigs( this.#cwd ),
415-
cliConfig = this.#getCliConfig( configs.cli ),
416414
editorConfig = await this.#getEditorConfig( {
417415
"fallbackToDefault": configs.package
418416
? Boolean( configs.cli )
@@ -479,7 +477,7 @@ export class LintFile {
479477
}
480478

481479
// trim
482-
if ( cliConfig?.lint.trim ) {
480+
if ( editorConfig.trim ) {
483481
this.#data = this.#data.trim();
484482
}
485483

@@ -600,9 +598,7 @@ export class LintFile {
600598
if ( editorConfig ) {
601599
prettierConfig.useTabs ??= editorConfig.indent_style === "tab";
602600
prettierConfig.tabWidth ??= editorConfig.tab_width;
603-
prettierConfig.printWidth ??= editorConfig.max_line_length === "off"
604-
? Infinity
605-
: editorConfig.max_line_length;
601+
prettierConfig.printWidth ??= editorConfig.max_line_length ?? Infinity;
606602
prettierConfig.endOfLine ??= editorConfig.end_of_line;
607603
}
608604

@@ -861,7 +857,12 @@ export class LintFile {
861857
"width": 100,
862858
"columns": {
863859
"severity": { "title": "Severity", "width": 10, "margin": [ 1, 0 ] },
864-
"line": { "title": "Line", "width": 10, "align": "end", "margin": [ 0, 1 ] },
860+
"line": {
861+
"title": "Line",
862+
"width": 10,
863+
"align": "end",
864+
"margin": [ 0, 1 ],
865+
},
865866
"description": { "title": "Desctiption", "margin": [ 1, 0 ] },
866867
},
867868
} );
@@ -995,7 +996,9 @@ export class LintFile {
995996
POSTCSS_CACHE[ preset ] = postcss( [ cssnano( { "preset": CSSNANO_PRESETS[ preset ] } ) ] );
996997
}
997998

998-
const res = await POSTCSS_CACHE[ preset ].process( this.#data, { "from": null } );
999+
const res = await POSTCSS_CACHE[ preset ].process( this.#data, {
1000+
"from": null,
1001+
} );
9991002

10001003
this.#data = res.toString();
10011004

@@ -1183,18 +1186,6 @@ export class LintFile {
11831186
}
11841187
}
11851188

1186-
#getCliConfig ( path ) {
1187-
if ( !path ) return;
1188-
1189-
this.#cache.cliConfigs ||= new Map();
1190-
1191-
if ( !this.#cache.cliConfigs.has( path ) ) {
1192-
this.#cache.cliConfigs.set( path, getCliConfig( path ) );
1193-
}
1194-
1195-
return this.#cache.cliConfigs.get( path );
1196-
}
1197-
11981189
async #getEditorConfig ( { fallbackToDefault } = {} ) {
11991190
this.#cache.editorConfigs ||= new Map();
12001191

resources/.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
max_line_length = off
10+
11+
max_line_length = unset
12+
trim = true
1113

1214
[*.{yaml,yml}]
1315
indent_size = 2

resources/cli.config.yaml

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

49-
lint:
50-
trim: true
51-
5249
release:
5350
enabled: false
5451
branches: [main]

resources/eslint/stylistic.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ export default Super =>
156156
rules[ "@stylistic/max-len" ] = [
157157
"error",
158158
{
159-
"code": editorConfig.max_line_length === "off"
160-
? Infinity
161-
: editorConfig.max_line_length,
159+
"code": editorConfig.max_line_length,
162160
"tabWidth": editorConfig.tab_width,
163161
},
164162
];

resources/schemas/cli.config.schema.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ 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-
112105
subPackages:
113106
anyOf:
114107
- type: "null"
@@ -258,4 +251,4 @@ properties:
258251
required: [location]
259252

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

0 commit comments

Comments
 (0)