Skip to content

Commit fd54415

Browse files
josephperrottAndrewKushnir
authored andcommitted
ci: complete migration to prettier formatting (angular#55580)
Format the remaining unformatted files in the repository PR Close angular#55580
1 parent 49d3062 commit fd54415

File tree

18 files changed

+47
-163
lines changed

18 files changed

+47
-163
lines changed

.devcontainer/recommended-devcontainer.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"devondcarew.bazel-code",
99
"gkalpak.aio-docs-utils",
1010
"ms-vscode.vscode-typescript-tslint-plugin",
11-
"xaver.clang-format",
1211
// The following extensions are useful when working on angular.io (i.e. inside the `aio/` directory).
1312
//"angular.ng-template",
1413
//"dbaeumer.vscode-eslint",

.ng-dev/format.mts

+5-84
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,8 @@ export const format: FormatConfig = {
77
'prettier': {
88
'matchers': [
99
'**/*.{yaml,yml}',
10-
'adev/**/*.{js,ts}',
11-
'devtools/**/*.{js,ts}',
12-
'integration/**/*.{js,ts}',
13-
'tools/**/*.{js,ts}',
14-
'modules/**/*.{js,ts}',
15-
'scripts/**/*.{js,ts}',
16-
'packages/animations/**/*.{js,ts}',
17-
'packages/bazel/**/*.{js,ts}',
18-
'packages/benchpress/**/*.{js,ts}',
19-
'packages/common/**/*.{js,ts}',
20-
'packages/compiler/**/*.{js,ts}',
21-
'packages/compiler-cli/**/*.{js,ts}',
22-
'packages/core/**/*.{js,ts}',
23-
'packages/docs/**/*.{js,ts}',
24-
'packages/elements/**/*.{js,ts}',
25-
'packages/examples/**/*.{js,ts}',
26-
'packages/forms/**/*.{js,ts}',
27-
'packages/language-service/**/*.{js,ts}',
28-
'packages/localize/**/*.{js,ts}',
29-
'packages/platform-browser/**/*.{js,ts}',
30-
'packages/platform-browser-dynamic/**/*.{js,ts}',
31-
'packages/platform-server/**/*.{js,ts}',
32-
'packages/misc/**/*.{js,ts}',
33-
'packages/private/**/*.{js,ts}',
34-
'packages/router/**/*.{js,ts}',
35-
'packages/service-worker/**/*.{js,ts}',
36-
'packages/upgrade/**/*.{js,ts}',
37-
'packages/zone.js/**/*.{js,ts}',
10+
'**/*.{js,ts}',
3811

39-
// Test cases contain non valid code.
40-
'!packages/compiler-cli/test/compliance/test_cases/**/*.{js,ts}',
4112
// Do not format d.ts files as they are generated
4213
'!**/*.d.ts',
4314
// Both third_party and .yarn are directories containing copied code which should
@@ -49,60 +20,10 @@ export const format: FormatConfig = {
4920
'!packages/core/src/i18n/locale_en.ts',
5021
'!packages/common/locales/closure-locale.ts',
5122
'!packages/common/src/i18n/currencies.ts',
52-
],
53-
},
54-
'clang-format': {
55-
'matchers': [
56-
'**/*.{js,ts}',
57-
// TODO: burn down format failures and remove aio and integration exceptions.
58-
'!aio/**',
59-
'!integration/**',
60-
// Both third_party and .yarn are directories containing copied code which should
61-
// not be modified.
62-
'!third_party/**',
63-
'!.yarn/**',
64-
// Do not format d.ts files as they are generated
65-
'!**/*.d.ts',
66-
// Do not format generated ng-dev script
67-
'!dev-infra/ng-dev.js',
68-
'!dev-infra/build-worker.js',
69-
// Do not format compliance test-cases since they must match generated code
70-
'!packages/compiler-cli/test/compliance/test_cases/**/*.js',
71-
// Do not format the locale files which are checked-in for Google3, but generated using
72-
// the `generate-locales-tool` from `packages/common/locales`.
73-
'!packages/core/src/i18n/locale_en.ts',
74-
'!packages/common/locales/closure-locale.ts',
75-
'!packages/common/src/i18n/currencies.ts',
76-
// Temporarily disable formatting for adev
77-
'!adev/**',
78-
79-
// Migrated to prettier
80-
'!devtools/**/*.{js,ts}',
81-
'!tools/**/*.{js,ts}',
82-
'!modules/**/*.{js,ts}',
83-
'!scripts/**/*.{js,ts}',
84-
'!packages/animations/**/*.{js,ts}',
85-
'!packages/bazel/**/*.{js,ts}',
86-
'!packages/benchpress/**/*.{js,ts}',
87-
'!packages/common/**/*.{js,ts}',
88-
'!packages/compiler/**/*.{js,ts}',
89-
'!packages/compiler-cli/**/*.{js,ts}',
90-
'!packages/core/**/*.{js,ts}',
91-
'!packages/docs/**/*.{js,ts}',
92-
'!packages/elements/**/*.{js,ts}',
93-
'!packages/examples/**/*.{js,ts}',
94-
'!packages/forms/**/*.{js,ts}',
95-
'!packages/language-service/**/*.{js,ts}',
96-
'!packages/localize/**/*.{js,ts}',
97-
'!packages/platform-browser/**/*.{js,ts}',
98-
'!packages/platform-browser-dynamic/**/*.{js,ts}',
99-
'!packages/platform-server/**/*.{js,ts}',
100-
'!packages/misc/**/*.{js,ts}',
101-
'!packages/private/**/*.{js,ts}',
102-
'!packages/router/**/*.{js,ts}',
103-
'!packages/service-worker/**/*.{js,ts}',
104-
'!packages/upgrade/**/*.{js,ts}',
105-
'!packages/zone.js/**/*.{js,ts}',
23+
// Test cases contain non valid code.
24+
'!packages/compiler-cli/test/compliance/test_cases/**/*.{js,ts}',
25+
// Ignore AIO as its pending removal.
26+
'!aio/**/*.{js,ts}',
10627
],
10728
},
10829
'buildifier': true,

.vscode/extensions.json

-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"recommendations": [
77
"BazelBuild.vscode-bazel",
88
"ms-vscode.vscode-typescript-tslint-plugin",
9-
"xaver.clang-format",
109
],
1110
}

.vscode/recommended-settings.json

-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
{
2-
// Format js and ts files on save with `clang-format.executable`
3-
// If `clang-format.executable` is not being used, these two settings should be removed otherwise it will break existing formatting.
4-
// You can instead run `yarn gulp format` to manually format your code.
52
"[javascript]": {
63
"editor.formatOnSave": true,
74
},
85
"[typescript]": {
96
"editor.formatOnSave": true,
107
},
11-
// Please install https://marketplace.visualstudio.com/items?itemName=xaver.clang-format to take advantage of `clang-format` in VSCode.
12-
// (See https://clang.llvm.org/docs/ClangFormat.html for more info `clang-format`.)
13-
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format",
148
// Exclude third party modules and build artifacts from the editor watchers/searches.
159
"files.watcherExclude": {
1610
"**/.git/objects/**": true,

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ To ensure consistency throughout the source code, keep these rules in mind as yo
207207
* All public API methods **must be documented**.
208208
* We follow [Google's JavaScript Style Guide][js-style-guide], but wrap all code at **100 characters**.
209209
210-
An automated formatter is available, see [DEVELOPER.md](docs/DEVELOPER.md#clang-format).
210+
An automated formatter is available, see [DEVELOPER.md](docs/DEVELOPER.md#formatting-your-source-code).
211211
212212
213213
## <a name="commit"></a> Commit Message Format

adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class HomeComponent {
4242
return;
4343
}
4444

45-
this.filteredLocationList = this.housingLocationList.filter(
46-
(housingLocation) => housingLocation?.city.toLowerCase().includes(text.toLowerCase()),
45+
this.filteredLocationList = this.housingLocationList.filter((housingLocation) =>
46+
housingLocation?.city.toLowerCase().includes(text.toLowerCase()),
4747
);
4848
}
4949
}

adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export class HomeComponent {
3838
return;
3939
}
4040

41-
this.filteredLocationList = this.housingLocationList.filter(
42-
(housingLocation) => housingLocation?.city.toLowerCase().includes(text.toLowerCase()),
41+
this.filteredLocationList = this.housingLocationList.filter((housingLocation) =>
42+
housingLocation?.city.toLowerCase().includes(text.toLowerCase()),
4343
);
4444
}
4545
}

browser-providers.conf.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ const customLaunchers = {
4343

4444
const sauceAliases = {
4545
'CI_REQUIRED': buildConfiguration('unitTest', 'SL', true),
46-
'CI_OPTIONAL': buildConfiguration('unitTest', 'SL', false)
46+
'CI_OPTIONAL': buildConfiguration('unitTest', 'SL', false),
4747
};
4848

4949
module.exports = {
50-
customLaunchers : customLaunchers,
51-
sauceAliases : sauceAliases,
50+
customLaunchers: customLaunchers,
51+
sauceAliases: sauceAliases,
5252
};
5353

5454
function buildConfiguration(type, target, required) {
5555
return Object.keys(config)
56-
.filter((item) => {
57-
const conf = config[item][type];
58-
return conf.required === required && conf.target === target;
59-
})
60-
.map((item) => target + '_' + item.toUpperCase());
56+
.filter((item) => {
57+
const conf = config[item][type];
58+
return conf.required === required && conf.target === target;
59+
})
60+
.map((item) => target + '_' + item.toUpperCase());
6161
}

devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/property-resolver/directive-property-resolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ export class DirectivePropertyResolver {
157157
propPointer = inputLabels.has(propName)
158158
? inputProps
159159
: outputLabels.has(propName)
160-
? outputProps
161-
: stateProps;
160+
? outputProps
161+
: stateProps;
162162
propPointer[propName] = this.directiveProperties[propName];
163163
});
164164

docs/CODING_STANDARDS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ built _with_ Angular. (Though you can follow them too if you really want).
77

88
The [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html) is the
99
basis for Angular's coding style, with additional guidance here pertaining to TypeScript. The team
10-
uses `clang-format` to automatically format code; automatic formatting is enforced by CI.
10+
uses `prettier` to automatically format code; automatic formatting is enforced by CI.
1111

1212
## Code practices
1313

docs/DEVELOPER.md

+2-26
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ PRs can only be merged if the code is formatted properly and all tests are passi
9191

9292
<a name="formatting-your-source-code">
9393
<a name="clang-format"></a>
94+
<a name="prettier"></a>
9495

9596
### Testing changes against a local library/project
9697

@@ -119,39 +120,14 @@ node --preserve-symlinks --preserve-symlinks-main node_modules/@angular/cli/lib/
119120

120121
## Formatting your source code
121122

122-
Angular uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format the source code.
123+
Angular uses [prettier](https://clang.llvm.org/docs/ClangFormat.html) to format the source code.
123124
If the source code is not properly formatted, the CI will fail and the PR cannot be merged.
124125

125126
You can automatically format your code by running:
126127
- `yarn ng-dev format changed [shaOrRef]`: format only files changed since the provided sha/ref. `shaOrRef` defaults to `main`.
127128
- `yarn ng-dev format all`: format _all_ source code
128129
- `yarn ng-dev format files <files..>`: format only provided files
129130

130-
A better way is to set up your IDE to format the changed file on each file save.
131-
132-
### VS Code
133-
1. Install [Clang-Format](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format) extension for VS Code.
134-
2. It will automatically pick up the settings from `.vscode/settings.json`.
135-
If you haven't already, create a `settings.json` file by following the instructions [here](../.vscode/README.md).
136-
137-
### WebStorm / IntelliJ
138-
1. Install the [ClangFormatIJ](https://plugins.jetbrains.com/plugin/8396-clangformatij) plugin
139-
1. Open `Preferences->Tools->clang-format`
140-
1. Find the field named "PATH"
141-
1. Add `<PATH_TO_YOUR_WORKSPACE>/angular/node_modules/clang-format/bin/<OS>/`
142-
where the OS options are: `darwin_x64`, `linux_x64`, and `win32`.
143-
144-
### Vim
145-
1. Install [Vim Clang-Format](https://github.com/rhysd/vim-clang-format).
146-
2. Create a [project-specific `.vimrc`](https://andrew.stwrt.ca/posts/project-specific-vimrc/) in
147-
your Angular directory containing
148-
149-
```vim
150-
let g:clang_format#command = '$ANGULAR_PATH/node_modules/.bin/clang-format'
151-
```
152-
153-
where `$ANGULAR_PATH` is an environment variable of the absolute path of your Angular directory.
154-
155131
## Linting/verifying your Source Code
156132

157133
You can check that your code is properly formatted and adheres to coding style by running:

goldens/public-api/manage.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ const argv = parser(process.argv.slice(2));
66
// The command the user would like to run, either 'accept' or 'test'
77
const USER_COMMAND = argv._[0];
88
// The shell command to query for all Public API guard tests.
9-
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD =
10-
`yarn -s bazel query --output label 'kind(nodejs_test, ...) intersect attr("tags", "api_guard", ...)'`
9+
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD = `yarn -s bazel query --output label 'kind(nodejs_test, ...) intersect attr("tags", "api_guard", ...)'`;
1110
// Bazel targets for testing Public API goldens
1211
process.stdout.write('Gathering all Public API targets');
1312
const ALL_PUBLIC_API_TESTS = exec(BAZEL_PUBLIC_API_TARGET_QUERY_CMD, {silent: true})
14-
.trim()
15-
.split('\n')
16-
.map(test => test.trim());
13+
.trim()
14+
.split('\n')
15+
.map((test) => test.trim());
1716
process.stdout.clearLine();
1817
process.stdout.cursorTo(0);
1918
// Bazel targets for generating Public API goldens
20-
const ALL_PUBLIC_API_ACCEPTS = ALL_PUBLIC_API_TESTS.map(test => `${test}.accept`);
19+
const ALL_PUBLIC_API_ACCEPTS = ALL_PUBLIC_API_TESTS.map((test) => `${test}.accept`);
2120

2221
/**
2322
* Run the provided bazel commands on each provided target individually.

gulpfile.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ function loadTask(fileName, taskName) {
1717
return task(gulp);
1818
}
1919

20-
2120
gulp.task('changelog:zonejs', loadTask('changelog-zonejs'));

karma-js.conf.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (!process.env.KARMA_WEB_TEST_MODE && isBazel && process.env.TEST_TARGET.inclu
1919
process.env.KARMA_WEB_TEST_MODE = 'SL_REQUIRED';
2020
}
2121

22-
module.exports = function(config) {
22+
module.exports = function (config) {
2323
const conf = {
2424
frameworks: ['jasmine'],
2525

@@ -55,11 +55,7 @@ module.exports = function(config) {
5555

5656
customLaunchers: browserProvidersConf.customLaunchers,
5757

58-
plugins: [
59-
'karma-jasmine',
60-
'karma-chrome-launcher',
61-
'karma-sourcemap-loader',
62-
],
58+
plugins: ['karma-jasmine', 'karma-chrome-launcher', 'karma-sourcemap-loader'],
6359

6460
preprocessors: {
6561
'**/*.js': ['sourcemap'],
@@ -126,7 +122,7 @@ module.exports = function(config) {
126122
// This slows-down tests/browser restarting and can decrease stability.
127123
// https://github.com/karma-runner/karma-sauce-launcher/blob/59b0c5c877448e064ad56449cd906743721c6b62/src/launcher/launcher.ts#L72-L79.
128124
require('saucelabs').default.prototype.downloadJobAsset = () =>
129-
Promise.resolve('<FAKE-LOGS>');
125+
Promise.resolve('<FAKE-LOGS>');
130126
}
131127
}
132128

@@ -155,7 +151,8 @@ module.exports = function(config) {
155151
break;
156152
default:
157153
throw new Error(
158-
`Unrecognized process.env.KARMA_WEB_TEST_MODE: ${process.env.KARMA_WEB_TEST_MODE}`);
154+
`Unrecognized process.env.KARMA_WEB_TEST_MODE: ${process.env.KARMA_WEB_TEST_MODE}`,
155+
);
159156
}
160157
} else {
161158
// Run the test locally

packages/circular-deps-test.conf.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
const path = require('path');
1010

1111
module.exports = {
12-
baseDir : '../',
13-
goldenFile : '../goldens/circular-deps/packages.json',
14-
glob : `./**/*.ts`,
12+
baseDir: '../',
13+
goldenFile: '../goldens/circular-deps/packages.json',
14+
glob: `./**/*.ts`,
1515
// Command that will be displayed if the golden needs to be updated.
16-
approveCommand : 'yarn ts-circular-deps:approve',
17-
resolveModule : resolveModule,
18-
ignoreTypeOnlyChecks : true,
16+
approveCommand: 'yarn ts-circular-deps:approve',
17+
resolveModule: resolveModule,
18+
ignoreTypeOnlyChecks: true,
1919
};
2020

2121
/**

packages/misc/angular-in-memory-web-api/src/backend-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ export abstract class BackendService {
727727
db instanceof Observable
728728
? db
729729
: typeof (db as any).then === 'function'
730-
? from(db as Promise<any>)
731-
: of(db);
730+
? from(db as Promise<any>)
731+
: of(db);
732732
db$.pipe(first()).subscribe((d: {}) => {
733733
this.db = d;
734734
this.dbReadySubject && this.dbReadySubject.next(true);

packages/zone.js/DEVELOPER.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Run tslint:
2121

2222
`yarn lint`
2323

24-
Run format with clang-format:
24+
Run format with prettier:
2525

2626
`yarn format`
2727

@@ -35,7 +35,7 @@ Before Commit
3535
Please make sure you pass all following checks before commit
3636

3737
- yarn gulp lint (tslint)
38-
- yarn gulp format (clang-format)
38+
- yarn gulp format (prettier)
3939
- yarn promisetest (promise a+ test)
4040
- yarn bazel test //packages/zone.js/... (all tests)
4141

tools/symbol-extractor/symbol_extractor_spec/hello_world_min_debug.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@
248248
return 'function' == typeof value
249249
? value.name || value
250250
: 'string' == typeof value
251-
? value
252-
: null == value
253-
? ''
254-
: '' + value;
251+
? value
252+
: null == value
253+
? ''
254+
: '' + value;
255255
}
256256
/**
257257
*@license

0 commit comments

Comments
 (0)