mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
Merge Master
This commit is contained in:
34
scripts/jison/lint.mts
Normal file
34
scripts/jison/lint.mts
Normal file
@@ -0,0 +1,34 @@
|
||||
/* eslint-disable no-console */
|
||||
import { readFile } from 'fs/promises';
|
||||
import { globby } from 'globby';
|
||||
import { ESLint } from 'eslint';
|
||||
// @ts-ignore no typings
|
||||
import jison from 'jison';
|
||||
|
||||
const linter = new ESLint({
|
||||
overrideConfig: { rules: { 'no-console': 'error' }, parser: '@typescript-eslint/parser' },
|
||||
useEslintrc: false,
|
||||
});
|
||||
|
||||
const lint = async (file: string): Promise<boolean> => {
|
||||
console.log(`Linting ${file}`);
|
||||
const jisonCode = await readFile(file, 'utf8');
|
||||
// @ts-ignore no typings
|
||||
const jsCode = new jison.Generator(jisonCode, { moduleType: 'amd' }).generate();
|
||||
const [result] = await linter.lintText(jsCode);
|
||||
if (result.errorCount > 0) {
|
||||
console.error(`Linting failed for ${file}`);
|
||||
console.error(result.messages);
|
||||
}
|
||||
return result.errorCount === 0;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const jisonFiles = await globby(['./packages/**/*.jison', '!./**/node_modules/**'], {
|
||||
dot: true,
|
||||
});
|
||||
const lintResults = await Promise.all(jisonFiles.map(lint));
|
||||
if (lintResults.some((result) => result === false)) {
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user