Skip to content

Commit

Permalink
Merge pull request #93 from jordanshatford/feat/autoformat-with-eslint
Browse files Browse the repository at this point in the history
feat(generate): auto format with eslint if available
  • Loading branch information
mrlubos authored Mar 20, 2024
2 parents 879fe97 + 0c59b9d commit 69506ac
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] => {
Expand Down
12 changes: 12 additions & 0 deletions test/bin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down

0 comments on commit 69506ac

Please sign in to comment.