From 40e8a9a4632e92dba89b583bc81759e773d07951 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 28 Apr 2021 11:43:10 -0400 Subject: [PATCH] build: set prettier as the code formatter with ng-dev tools Code formatting for TypeScript, JavaScript, JSON, YAML, and Markdown files will now be enforced by the ng-dev tools via prettier. A CI check is now in place as well to verify the formatting for PRs. --- .circleci/config.yml | 3 +++ .husky/pre-commit | 4 ++++ .ng-dev/config.ts | 1 + .ng-dev/format.ts | 10 ++++++++++ .prettierignore | 5 ++++- package.json | 2 +- yarn.lock | 4 ++-- 7 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 .husky/pre-commit create mode 100644 .ng-dev/format.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index bcab988200a5..980ea00d9c68 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -172,6 +172,9 @@ jobs: else echo "This build is not over a PR, nothing to do." fi + - run: + name: Validate Code Formatting + command: yarn -s ng-dev format changed <> --check - run: command: yarn -s admin validate diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000000..84611a58eec9 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname $0)/_/husky.sh" + +yarn -s ng-dev format staged; \ No newline at end of file diff --git a/.ng-dev/config.ts b/.ng-dev/config.ts index a5d99ef26f13..2a1f8e802316 100644 --- a/.ng-dev/config.ts +++ b/.ng-dev/config.ts @@ -1,3 +1,4 @@ export { commitMessage } from './commit-message'; +export { format } from './format'; export { github } from './github'; export { merge } from './merge'; diff --git a/.ng-dev/format.ts b/.ng-dev/format.ts new file mode 100644 index 000000000000..39479cbdbe66 --- /dev/null +++ b/.ng-dev/format.ts @@ -0,0 +1,10 @@ +import { FormatConfig } from '@angular/dev-infra-private/format/config'; + +/** + * Configuration for the `ng-dev format` command. + */ +export const format: FormatConfig = { + 'prettier': { + matchers: ['**/*.{ts,js,json,yml,yaml,md}'] + }, +} diff --git a/.prettierignore b/.prettierignore index 04975244c3e8..77f72e2429cd 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,9 @@ /bazel-out/ +/docs/design/analytics.md /dist-schema/ -/etc/api +/etc/api/ +/packages/angular_devkit/build_angular/test/ +/packages/angular_devkit/core/src/workspace/json/test/ /tests/ /README.md /CONTRIBUTING.md diff --git a/package.json b/package.json index 7712d9e8ad41..c4861438d6d2 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@angular/compiler": "12.0.0-rc.0", "@angular/compiler-cli": "12.0.0-rc.0", "@angular/core": "12.0.0-rc.0", - "@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#8e28890cecf2ac5d0d5ca590fafc323dea5f133f", + "@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#0d0c8c43a08fa6d52540283a607c7289e8165c9e", "@angular/forms": "12.0.0-rc.0", "@angular/localize": "12.0.0-rc.0", "@angular/material": "11.2.10", diff --git a/yarn.lock b/yarn.lock index c9ea53f20c7d..dccf1f231011 100644 --- a/yarn.lock +++ b/yarn.lock @@ -84,9 +84,9 @@ dependencies: tslib "^2.0.0" -"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#8e28890cecf2ac5d0d5ca590fafc323dea5f133f": +"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#0d0c8c43a08fa6d52540283a607c7289e8165c9e": version "0.0.0" - resolved "https://github.com/angular/dev-infra-private-builds.git#8e28890cecf2ac5d0d5ca590fafc323dea5f133f" + resolved "https://github.com/angular/dev-infra-private-builds.git#0d0c8c43a08fa6d52540283a607c7289e8165c9e" dependencies: "@angular/benchpress" "0.2.1" "@bazel/buildifier" "^4.0.1"