Skip to content

Use prettier #18700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print-width: 120
trailing-comma: all
tab-width: 4
# Thanks prettier-miscellaneous.
# This doesn't seem to be documented though.
# https://github.com/arijs/prettier-miscellaneous/pull/21
break-before-else: true
37 changes: 27 additions & 10 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,20 +1045,37 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) =
sendNextFile(files, child, callback, failures);
}

gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
if (fold.isTravis()) console.log(fold.start("lint"));
const fileMatcher = cmdLineOptions["files"];
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
console.log("Linting: " + cmd);
child_process.execSync(cmd, { stdio: [0, 1, 2] });
if (fold.isTravis()) console.log(fold.end("lint"));
gulp.task("prettier", "Runs prettier.", [], () => {
withFold("prettier", () => {
const cmd = "node node_modules/prettier-miscellaneous/bin/prettier --write src/**/*.ts";
child_process.execSync(cmd, { stdio: [0, 1, 2] });
});
});

gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules", "pretty"], () => {
withFold("lint", () => {
const fileMatcher = cmdLineOptions["files"];
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
console.log("Linting: " + cmd);
child_process.execSync(cmd, { stdio: [0, 1, 2] });
});
});

gulp.task("default", "Runs 'local'", ["local"]);

gulp.task("watch", "Watches the src/ directory for changes and executes runtests-parallel.", [], () => {
gulp.watch("src/**/*.*", ["runtests-parallel"]);
});

function withFold(name: string, action: () => void): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not withFold<T>(name: string, action: () => T): () => T, making the body:

return () => {
   if (fold.isTravis()) {
        console.log(fold.start(name));
    }
    const result = action();
    if (fold.isTravis()) {
        console.log(fold.end(name));
    }
    return result;
}

Allowing you to simply wrap whatever gulp task function you please? Should reduce nesting a bit, too (and clean up the diff).
Technically the fold won't work correctly for stream or promise return values... but w/e, it doesn't already and the higher-order definition looks a bit nicer at the use-site.

if (fold.isTravis()) {
console.log(fold.start(name));
}
action();
if (fold.isTravis()) {
console.log(fold.end(name));
}
}
48 changes: 37 additions & 11 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,17 +1219,43 @@ function spawnLintWorker(files, callback) {
sendNextFile(files, child, callback, failures);
}

task("prettier", [], () => {
withFold("prettier", endFold => {
const cmd = "node node_modules/prettier-miscellaneous/bin/prettier --write src/**/*.ts";
jake.exec([cmd], { interactive: true }, () => {
endFold();
complete();
});
});
});

desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
task("lint", ["build-rules"], () => {
if (fold.isTravis()) console.log(fold.start("lint"));
const fileMatcher = process.env.f || process.env.file || process.env.files;
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
console.log("Linting: " + cmd);
jake.exec([cmd], { interactive: true }, () => {
if (fold.isTravis()) console.log(fold.end("lint"));
complete();
task("lint", ["build-rules", "prettier"], () => {
withFold("lint", endFold => {
const fileMatcher = process.env.f || process.env.file || process.env.files;
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
console.log("Linting: " + cmd);
jake.exec([cmd], { interactive: true }, () => {
endFold();
complete();
});
});
});

/**
* @param {string} name
* @param {(endFold: () => void) => void} action
*/
function withFold(name, action) {
if (fold.isTravis()) {
console.log(fold.start(name));
}
action(() => {
if (fold.isTravis()) {
console.log(fold.end(name));
}
});
}
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"browser-resolve": "^1.11.2",
"browserify": "latest",
"chai": "latest",
"colors": "latest",
"convert-source-map": "latest",
"del": "latest",
"gulp": "3.X",
Expand All @@ -62,24 +63,27 @@
"gulp-newer": "latest",
"gulp-sourcemaps": "latest",
"gulp-typescript": "latest",
"husky": "latest",
"istanbul": "latest",
"jake": "latest",
"lint-staged": "latest",
"merge2": "latest",
"minimist": "latest",
"mkdirp": "latest",
"mocha": "latest",
"mocha-fivemat-progress-reporter": "latest",
"prettier-miscellaneous": "latest",
"q": "latest",
"run-sequence": "latest",
"sorcery": "latest",
"through2": "latest",
"travis-fold": "latest",
"ts-node": "latest",
"tslint": "latest",
"colors": "latest",
"typescript": "next"
},
"scripts": {
"precommit": "lint-staged",
"pretest": "jake tests",
"test": "jake runtests-parallel",
"build": "npm run build:compiler && npm run build:tests",
Expand All @@ -92,6 +96,12 @@
"lint": "jake lint",
"setup-hooks": "node scripts/link-hooks.js"
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write",
"git add"
]
},
"browser": {
"fs": false,
"os": false,
Expand Down