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

fix(linter): handle non-JSON eslintrc files when updating overrides #19026

Merged
merged 1 commit into from
Sep 6, 2023
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 e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('Node Applications', () => {
}
).toString();
expect(additionalResult).toContain('Hello Additional World!');
}, 60000);
}, 300_000);

it('should be able to generate an empty application with variable in .env file', async () => {
const originalEnvPort = process.env.PORT;
Expand Down
37 changes: 37 additions & 0 deletions packages/linter/src/generators/utils/eslint-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
baseEsLintConfigFile,
eslintConfigFileWhitelist,
findEslintFile,
lintConfigHasOverride,
} from './eslint-file';

import { Tree } from '@nx/devkit';
Expand Down Expand Up @@ -36,4 +37,40 @@ describe('@nx/linter:eslint-file', () => {
}
);
});

describe('lintConfigHasOverride', () => {
it('should return true when override exists in eslintrc format', () => {
tree.write(
'.eslintrc.json',
'{"overrides": [{ "files": ["*.ts"], "rules": {} }]}'
);
expect(
lintConfigHasOverride(
tree,
'.',
(o) => {
return o.files?.includes('*.ts');
},
false
)
).toBe(true);
});

it('should return false when eslintrc is not in JSON format', () => {
tree.write(
'.eslintrc.js',
'module.exports = {overrides: [{ files: ["*.ts"], rules: {} }]};'
);
expect(
lintConfigHasOverride(
tree,
'.',
(o) => {
return o.files?.includes('*.ts');
},
false
)
).toBe(false);
});
});
});
5 changes: 4 additions & 1 deletion packages/linter/src/generators/utils/eslint-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ export function lintConfigHasOverride(
root,
isBase ? baseEsLintConfigFile : '.eslintrc.json'
);
return readJson(tree, fileName).overrides?.some(lookup) || false;

return tree.exists(fileName)
? readJson(tree, fileName).overrides?.some(lookup) || false
: false;
}
}

Expand Down