1.2 KB43 lines
Blame
1/* eslint-disable no-console */
2import { readFile } from 'fs/promises';
3import { globby } from 'globby';
4import { ESLint } from 'eslint';
5// @ts-ignore no typings
6import jison from 'jison';
7
8const linter = new ESLint({
9 // @ts-expect-error ESLint types are incorrect
10 overrideConfigFile: true,
11 overrideConfig: { rules: { 'no-console': 'error' } },
12});
13
14const lint = async (file: string): Promise<boolean> => {
15 console.log(`Linting ${file}`);
16 const jisonCode = await readFile(file, 'utf8');
17 // @ts-ignore no typings
18 const generator = new jison.Generator(jisonCode, { moduleType: 'amd' });
19 const jsCode = generator.generate();
20 const [result] = await linter.lintText(jsCode);
21 if (result.errorCount > 0) {
22 console.error(`Linting failed for ${file}`);
23 console.error(result.messages);
24 }
25 if (generator.conflicts > 0) {
26 console.error(`Linting failed for ${file}. Conflicts found in grammar`);
27 return false;
28 }
29 return result.errorCount === 0;
30};
31
32const main = async () => {
33 const jisonFiles = await globby(['./packages/**/*.jison', '!./**/node_modules/**'], {
34 dot: true,
35 });
36 const lintResults = await Promise.all(jisonFiles.map(lint));
37 if (lintResults.includes(false)) {
38 process.exit(1);
39 }
40};
41
42void main();
43