fix(linter): add @nrwl/linter as a devDependency and error on improper enum schema (#4634)

This commit is contained in:
Jason Jean 2021-01-28 16:30:10 -05:00 committed by GitHub
parent 14503c27c9
commit b36c4b5cc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 7 deletions

View File

@ -105,7 +105,7 @@ describe('Linter', () => {
/'tslint' option is no longer supported/
);
expect(() => runCLI(`lint ${myapp} --linter=random`)).toThrow(
/Schema validation failed/
/'random' should be one of eslint,tslint/
);
}, 1000000);

View File

@ -377,12 +377,20 @@ describe('app', () => {
expect(eslintJson.extends).toEqual(
expect.arrayContaining(['plugin:@nrwl/nx/react'])
);
expect(packageJson).toMatchObject({
devDependencies: {
'eslint-plugin-react': expect.anything(),
'eslint-plugin-react-hooks': expect.anything(),
},
});
expect(packageJson.devDependencies.eslint).toBeDefined();
expect(packageJson.devDependencies['@nrwl/linter']).toBeDefined();
expect(packageJson.devDependencies['@nrwl/eslint-plugin-nx']).toBeDefined();
expect(packageJson.devDependencies['eslint-plugin-react']).toBeDefined();
expect(
packageJson.devDependencies['eslint-plugin-react-hooks']
).toBeDefined();
expect(
packageJson.devDependencies['@typescript-eslint/parser']
).toBeDefined();
expect(
packageJson.devDependencies['@typescript-eslint/eslint-plugin']
).toBeDefined();
expect(packageJson.devDependencies['eslint-config-prettier']).toBeDefined();
});
describe('--class-component', () => {

View File

@ -226,6 +226,14 @@ function validateProperty(
`Property '${propName}' does not match the schema. '${value}' should be a '${schema.type}'.`
);
}
if (schema.enum && !schema.enum.includes(value)) {
throw new SchemaError(
`Property '${propName}' does not match the schema. '${value}' should be one of ${schema.enum.join(
','
)}.`
);
}
} else if (Array.isArray(value)) {
if (schema.type !== 'array') throwInvalidSchema(propName, schema);
value.forEach((valueInArray) =>

View File

@ -115,6 +115,7 @@ export function addLintFiles(
: {}),
},
{
'@nrwl/linter': nxVersion,
'@nrwl/eslint-plugin-nx': nxVersion,
'@typescript-eslint/parser': typescriptESLintVersion,
'@typescript-eslint/eslint-plugin': typescriptESLintVersion,