Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generate): auto format with eslint if available #93

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading