diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8fae4198..fda7d2f01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: run: npm run build - name: Run linter - run: npm run eslint + run: npm run lint - name: Run unit tests run: npm run test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f2c3c529..08b69906d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ https://help.github.com/articles/using-pull-requests 2. Create your patch or feature 3. Ensure the builds work by running: `npm run build` 4. Ensure the tests will pass by running: `npm run test` -5. Ensure the code is formatted by running: `npm run eslint:fix` +5. Ensure the code is formatted by running: `npm run lint:fix` 6. Commit your changes using a descriptive commit message After your Pull Request is created, it will automatically be build and tested in GitHub actions. Once successful it will be ready for review. diff --git a/package.json b/package.json index ae4595560..3aeeac8b5 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp", "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node", "clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache", - "eslint:fix": "eslint . --fix", - "eslint": "eslint .", + "lint:fix": "eslint . --fix", + "lint": "eslint .", "prepublishOnly": "npm run build", "test": "jest --selectProjects UNIT", "test:coverage": "jest --selectProjects UNIT --coverage", diff --git a/src/index.ts b/src/index.ts index a490c5c4c..6877a2406 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,6 +38,11 @@ const formatClient = (options: Config, dependencies: Dependencies) => { console.log('✨ Running Prettier'); sync('prettier', ['--ignore-unknown', options.output, '--write', '--ignore-path', './.prettierignore']); } + + if (dependencies.eslint) { + console.log('✨ Running Eslint'); + sync('eslint', [options.output, '--fix', '--quiet', '--ignore-path', './.eslintignore']); + } }; const inferClient = (dependencies: Dependencies): Config['client'] => { diff --git a/test/bin.spec.ts b/test/bin.spec.ts index a210e8544..a6cf6260f 100755 --- a/test/bin.spec.ts +++ b/test/bin.spec.ts @@ -146,6 +146,18 @@ describe('bin', () => { expect(result.stderr.toString()).toBe(''); }); + it('auto fixs output with Eslint', async () => { + const result = sync('node', [ + './bin/index.js', + '--input', + './test/spec/v3.json', + '--output', + './test/generated/bin', + ]); + expect(result.stdout.toString()).toContain('Eslint'); + expect(result.stderr.toString()).toBe(''); + }); + it('throws error without parameters', async () => { const result = sync('node', ['./bin/index.js', '--no-write']); expect(result.stdout.toString()).toBe('');