Fix trailing new line

This commit is contained in:
Michaël Lemaire 2021-09-05 23:58:08 +02:00
parent 98635fca28
commit de06f0839e
4 changed files with 20 additions and 13 deletions

View file

@ -6,4 +6,4 @@ end_of_line = lf
insert_final_newline = true insert_final_newline = true
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
trim_trailing_whitespace = true trim_trailing_whitespace = true

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
deno.d.ts deno.d.ts
.vscode .vscode
.local .local

2
run
View file

@ -16,4 +16,4 @@ else
fi fi
denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@" denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"
exec deno $denocmd $denoargs exec deno $denocmd $denoargs

View file

@ -42,6 +42,13 @@ export class ProjectNormalizer {
await this.formatPath(path); await this.formatPath(path);
} }
async writeLines(path: string, lines: string[]) {
await this.sys.writeTextFile(
path,
lines.concat("").join("\n"),
);
}
async formatPath(path: string) { async formatPath(path: string) {
await this.sys.run({ await this.sys.run({
cmd: ["./run", "fmt", "-q", path], cmd: ["./run", "fmt", "-q", path],
@ -49,7 +56,7 @@ export class ProjectNormalizer {
} }
async updateRunScript() { async updateRunScript() {
await this.sys.writeTextFile( await this.writeLines(
"run", "run",
[ [
`#!/bin/sh`, `#!/bin/sh`,
@ -71,7 +78,7 @@ export class ProjectNormalizer {
``, ``,
`denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"`, `denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"`,
`exec deno $denocmd $denoargs`, `exec deno $denocmd $denoargs`,
].join("\n"), ],
); );
await this.sys.chmod("run", 0o755); await this.sys.chmod("run", 0o755);
} }
@ -86,7 +93,7 @@ export class ProjectNormalizer {
} }
async updateEditorConfig() { async updateEditorConfig() {
await this.sys.writeTextFile( await this.writeLines(
".editorconfig", ".editorconfig",
[ [
`root = true`, `root = true`,
@ -98,7 +105,7 @@ export class ProjectNormalizer {
`indent_style = space`, `indent_style = space`,
`indent_size = 2`, `indent_size = 2`,
`trim_trailing_whitespace = true`, `trim_trailing_whitespace = true`,
].join("\n"), ],
); );
} }
@ -168,25 +175,25 @@ export class ProjectNormalizer {
} }
async updateGitIgnore() { async updateGitIgnore() {
await this.sys.writeTextFile( await this.writeLines(
".gitignore", ".gitignore",
[ [
`deno.d.ts`, `deno.d.ts`,
`.vscode`, `.vscode`,
`.local`, `.local`,
].join("\n"), ],
); );
} }
async updateGitHooks() { async updateGitHooks() {
await this.sys.writeTextFile( await this.writeLines(
".git/hooks/pre-commit", ".git/hooks/pre-commit",
[ [
`#!/bin/sh`, `#!/bin/sh`,
`set -e`, `set -e`,
`./run fmt --check`, `./run fmt --check`,
`./run test`, `./run test`,
].join("\n"), ],
); );
await this.sys.chmod(".git/hooks/pre-commit", 0o755); await this.sys.chmod(".git/hooks/pre-commit", 0o755);
} }
@ -203,13 +210,13 @@ export class ProjectNormalizer {
} }
} }
} }
await this.sys.writeTextFile( await this.writeLines(
"README.md", "README.md",
[ [
`# typescript/${project}`, `# typescript/${project}`,
`[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/${project}?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=${project})`, `[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/${project}?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=${project})`,
sections, sections,
].join("\n"), ],
); );
await this.formatPath("README.md"); await this.formatPath("README.md");
} }