Skip to content

Commit 69506ac

Browse files
authored
Merge pull request ferdikoomen#93 from jordanshatford/feat/autoformat-with-eslint
feat(generate): auto format with eslint if available
2 parents 879fe97 + 0c59b9d commit 69506ac

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: npm run build
3131

3232
- name: Run linter
33-
run: npm run eslint
33+
run: npm run lint
3434

3535
- name: Run unit tests
3636
run: npm run test

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ https://help.github.com/articles/using-pull-requests
3838
2. Create your patch or feature
3939
3. Ensure the builds work by running: `npm run build`
4040
4. Ensure the tests will pass by running: `npm run test`
41-
5. Ensure the code is formatted by running: `npm run eslint:fix`
41+
5. Ensure the code is formatted by running: `npm run lint:fix`
4242
6. Commit your changes using a descriptive commit message
4343

4444
After your Pull Request is created, it will automatically be build and tested in GitHub actions. Once successful it will be ready for review.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp",
5151
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node",
5252
"clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache",
53-
"eslint:fix": "eslint . --fix",
54-
"eslint": "eslint .",
53+
"lint:fix": "eslint . --fix",
54+
"lint": "eslint .",
5555
"prepublishOnly": "npm run build",
5656
"test": "jest --selectProjects UNIT",
5757
"test:coverage": "jest --selectProjects UNIT --coverage",

src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const formatClient = (options: Config, dependencies: Dependencies) => {
3838
console.log('✨ Running Prettier');
3939
sync('prettier', ['--ignore-unknown', options.output, '--write', '--ignore-path', './.prettierignore']);
4040
}
41+
42+
if (dependencies.eslint) {
43+
console.log('✨ Running Eslint');
44+
sync('eslint', [options.output, '--fix', '--quiet', '--ignore-path', './.eslintignore']);
45+
}
4146
};
4247

4348
const inferClient = (dependencies: Dependencies): Config['client'] => {

test/bin.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ describe('bin', () => {
146146
expect(result.stderr.toString()).toBe('');
147147
});
148148

149+
it('auto fixs output with Eslint', async () => {
150+
const result = sync('node', [
151+
'./bin/index.js',
152+
'--input',
153+
'./test/spec/v3.json',
154+
'--output',
155+
'./test/generated/bin',
156+
]);
157+
expect(result.stdout.toString()).toContain('Eslint');
158+
expect(result.stderr.toString()).toBe('');
159+
});
160+
149161
it('throws error without parameters', async () => {
150162
const result = sync('node', ['./bin/index.js', '--no-write']);
151163
expect(result.stdout.toString()).toBe('');

0 commit comments

Comments
 (0)