Skip to content

Commit a44979e

Browse files
authored
Merge pull request #44 from ember-cli/setup-prettier
Add prettier so our PRs don't have accidental changes
2 parents 3f783c9 + d950a1c commit a44979e

File tree

11 files changed

+93
-45
lines changed

11 files changed

+93
-45
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ env:
1313
CI: true
1414

1515
jobs:
16+
lint:
17+
name: Lint
18+
timeout-minutes: 5
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: pnpm/action-setup@v4
23+
- uses: actions/setup-node@v4
24+
with:
25+
cache: pnpm
26+
- name: Install Dependencies
27+
run: pnpm install --frozen-lockfile
28+
- run: pnpm lint
29+
1630
tests:
1731
name: Tests
1832
timeout-minutes: 5

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.yaml
2+
*.yml
3+
*.md
4+
files/
5+
tests/fixtures/
6+
7+
node_modules/
8+

.prettierrc.cjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = {
4+
printWidth: 100,
5+
overrides: [
6+
{
7+
files: '*.{js,ts,mjs,mts,cjs,cts}',
8+
options: {
9+
singleQuote: true,
10+
},
11+
},
12+
],
13+
};

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
if (options.ciProvider !== 'github') {
5050
files = files.filter((file) => file.indexOf('.github') < 0);
5151
}
52-
52+
5353
if (!options.typescript) {
5454
let ignoredFiles = ['tsconfig.json'];
5555

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
},
1212
"license": "MIT",
1313
"author": "",
14-
"scripts": {},
15-
"dependencies": {},
14+
"scripts": {
15+
"lint": "prettier --check .",
16+
"format": "prettier --write ."
17+
},
1618
"devDependencies": {
19+
"prettier": "^3.5.3",
1720
"release-plan": "^0.16.0"
1821
},
1922
"packageManager": "pnpm@10.6.5"

pnpm-lock.yaml

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/helpers/fixtures.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function readFixture(
2727
* Which fixture set to use
2828
*/
2929
scenario?: string;
30-
}
30+
},
3131
) {
3232
let scenario = options?.scenario ?? 'default';
3333
let fixtureFilePath = path.isAbsolute(file) ? file : path.join(fixturesPath, scenario, file);
@@ -36,7 +36,7 @@ export async function readFixture(
3636

3737
assert(
3838
exists,
39-
`Fixture file '${file}' does not exist. To make this work, place a new file '${file}' in the 'tests/fixtures/${scenario}' directory. Checked the absolute path: '${fixtureFilePath}'.`
39+
`Fixture file '${file}' does not exist. To make this work, place a new file '${file}' in the 'tests/fixtures/${scenario}' directory. Checked the absolute path: '${fixtureFilePath}'.`,
4040
);
4141

4242
let contents = await fs.readFile(fixtureFilePath);
@@ -48,15 +48,15 @@ export async function writeFixture(
4848
/**
4949
* Which file within in the fixture-set / scenario to read
5050
*/
51-
file: string,
51+
file: string,
5252
contents: string,
53-
options?: {
53+
options?: {
5454
/**
5555
* Which fixture set to use
5656
*/
57-
scenario?: string }) {
58-
59-
57+
scenario?: string;
58+
},
59+
) {
6060
let scenario = options?.scenario ?? 'default';
6161
let fixtureFilePath = path.isAbsolute(file) ? file : path.join(fixturesPath, scenario, file);
6262

@@ -85,7 +85,7 @@ export async function copyFixture(
8585
* The working directory to use for the relative paths. Defaults to process.cwd() (node default)
8686
*/
8787
cwd?: string;
88-
}
88+
},
8989
) {
9090
let scenario = options?.scenario ?? 'default';
9191
let fixtureFile = options?.file ?? newFile;
@@ -99,7 +99,7 @@ export async function copyFixture(
9999

100100
assert(
101101
exists,
102-
`Fixture path '${fixtureFile}' does not exist. To make this work, place a new file/folder '${fixtureFile}' in the 'tests/fixtures/${scenario}' directory. Checked the absolute path: '${fullFixturePath}'.`
102+
`Fixture path '${fixtureFile}' does not exist. To make this work, place a new file/folder '${fixtureFile}' in the 'tests/fixtures/${scenario}' directory. Checked the absolute path: '${fullFixturePath}'.`,
103103
);
104104

105105
if (await isDirectory(fullFixturePath)) {

tests/helpers/meta-helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export class AddonHelper {
2828
#args: string[];
2929
#fixtures: AddonFixtureHelper | undefined;
3030

31-
constructor(options: {
32-
args?: string[];
33-
scenario?: string;
34-
packageManager: 'pnpm' | 'npm';
35-
}) {
31+
constructor(options: { args?: string[]; scenario?: string; packageManager: 'pnpm' | 'npm' }) {
3632
this.#args = options.args || [];
3733
this.#scenario = options.scenario || 'default';
3834
this.#packageManager = options.packageManager;
@@ -85,7 +81,7 @@ export class AddonHelper {
8581

8682
assert(
8783
this.#tmpDir,
88-
"Cannot clean without a tmpDir. Was the Addon Helper's `setup` method called to generate the addon?"
84+
"Cannot clean without a tmpDir. Was the Addon Helper's `setup` method called to generate the addon?",
8985
);
9086

9187
await fs.rm(this.#tmpDir, { recursive: true, force: true });

tests/rollup-build-tests/declarations.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ describe(`declarations-configuration`, () => {
3232
it('there are no top-level files, only nested in folders', async () => {
3333
await fse.rm(path.join(helper.projectRoot, 'src'), { recursive: true });
3434
await fse.mkdirp(path.join(helper.projectRoot, 'src/components'));
35-
await fs.writeFile(path.join(helper.projectRoot, 'src/components/example.ts'), '/* empty file */');
35+
await fs.writeFile(
36+
path.join(helper.projectRoot, 'src/components/example.ts'),
37+
'/* empty file */',
38+
);
3639

3740
let buildResult = await helper.build();
3841

3942
expect(buildResult.exitCode).toEqual(0);
4043

41-
expect(await dirContents(declarationsDir)).to.deep.equal([
42-
'components',
43-
]);
44+
expect(await dirContents(declarationsDir)).to.deep.equal(['components']);
4445

4546
expect(await dirContents(path.join(declarationsDir, 'components'))).to.deep.equal([
4647
'example.d.ts',
47-
'example.d.ts.map'
48+
'example.d.ts.map',
4849
]);
4950
});
5051
});

tests/smoke-tests/defaults.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path, { join } from 'node:path';
33
import tmp from 'tmp-promise';
44
let localEmberCli = require.resolve('ember-cli/bin/ember');
55
import { beforeAll, describe, expect, it } from 'vitest';
6-
import {execa } from 'execa';
6+
import { execa } from 'execa';
77
import fixturify from 'fixturify';
88

99
const blueprintPath = path.join(__dirname, '../..');
@@ -13,7 +13,7 @@ import {
1313
assertGeneratedCorrectly,
1414
dirContents,
1515
matchesFixture,
16-
SUPPORTED_PACKAGE_MANAGERS
16+
SUPPORTED_PACKAGE_MANAGERS,
1717
} from '../helpers.js';
1818
import { existsSync } from 'node:fs';
1919

@@ -22,12 +22,14 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
2222
let tmpDir: string;
2323
let addonDir: string;
2424
let addonName = 'my-addon';
25-
25+
2626
beforeAll(async () => {
2727
tmpDir = (await tmp.dir()).path;
28-
addonDir = join(tmpDir, addonName)
29-
await execa({cwd: tmpDir})`${localEmberCli} addon ${addonName} -b ${blueprintPath} --skip-npm --skip-git --prefer-local true --${packageManager}`;
30-
await execa({cwd: addonDir})`${packageManager} install`
28+
addonDir = join(tmpDir, addonName);
29+
await execa({
30+
cwd: tmpDir,
31+
})`${localEmberCli} addon ${addonName} -b ${blueprintPath} --skip-npm --skip-git --prefer-local true --${packageManager}`;
32+
await execa({ cwd: addonDir })`${packageManager} install`;
3133
});
3234

3335
it('is using the correct packager', async () => {
@@ -59,7 +61,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
5961
});
6062
await matchesFixture('CONTRIBUTING.md', {
6163
cwd: addonDir,
62-
scenario: 'pnpm'
64+
scenario: 'pnpm',
6365
});
6466
await matchesFixture('.npmrc', {
6567
cwd: addonDir,
@@ -87,7 +89,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
8789
// Tests are additive, so when running them in order, we want to check linting
8890
// before we add files from fixtures
8991
it('lints with no fixtures all pass', async () => {
90-
let { exitCode } = await execa({cwd: addonDir})`pnpm lint`;
92+
let { exitCode } = await execa({ cwd: addonDir })`pnpm lint`;
9193

9294
expect(exitCode).toEqual(0);
9395
});
@@ -103,31 +105,32 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
103105
// It's important to keep this along with the tests,
104106
// so that we can have confidence that the lints aren't destructively changing
105107
// the files in a way that would break consumers
106-
let { exitCode } = await execa({cwd: addonDir})`${packageManager} run lint:fix`;
108+
let { exitCode } = await execa({ cwd: addonDir })`${packageManager} run lint:fix`;
107109

108110
expect(exitCode).toEqual(0);
109111

110-
let buildResult = await execa({cwd: addonDir})`${packageManager} run build`;
112+
let buildResult = await execa({ cwd: addonDir })`${packageManager} run build`;
111113

112114
expect(buildResult.exitCode).toEqual(0);
113115

114116
let contents = await dirContents(join(addonDir, 'dist'));
115117

116118
expect(contents).to.deep.equal(['_app_', 'components', 'index.js', 'index.js.map']);
117119

118-
let testResult = await await execa({cwd: addonDir})`${packageManager} run test`;
120+
let testResult = await await execa({ cwd: addonDir })`${packageManager} run test`;
119121

120122
expect(testResult.exitCode).toEqual(0);
121123

122-
expect(testResult.stdout).includes(`# tests 2
124+
expect(testResult.stdout).includes(
125+
`# tests 2
123126
# pass 2
124127
# skip 0
125128
# todo 0
126129
# fail 0
127130
128-
# ok`, testResult.stdout);
129-
130-
131+
# ok`,
132+
testResult.stdout,
133+
);
131134
});
132135
});
133136
}

0 commit comments

Comments
 (0)