Skip to content

Commit

Permalink
fix tests and eslint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez committed Nov 25, 2024
1 parent 42a6e0c commit 1218b8e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions tools/generate-rule-indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

import prettier from 'prettier';
import { readdir, writeFile } from 'fs/promises';
import { join, dirname } from 'node:path/posix';
import { fileURLToPath, pathToFileURL } from 'node:url';
Expand Down Expand Up @@ -50,6 +50,17 @@ const RULES_FOLDER = join(
dirname(toUnixPath(fileURLToPath(import.meta.url))),
'../packages/jsts/src/rules/',
);

const prettierOpts = {
printWidth: 100,
trailingComma: 'all',
singleQuote: true,
arrowParens: 'avoid',
endOfLine: 'lf',
} as const;

const allRulesIndex = join(RULES_FOLDER, './rules.ts');
const pluginRulesIndex = join(RULES_FOLDER, './plugin-rules.ts');
const ruleRegex = /^S\d+$/;

const allRules: string[] = [];
Expand All @@ -73,19 +84,25 @@ for (const file of files) {
const sonarKeySorter = (a, b) => (parseInt(a.substring(1)) < parseInt(b.substring(1)) ? -1 : 1);

await writeFile(
join(RULES_FOLDER, './rules.ts'),
`${header}\n\n// DO NOT EDIT! This file was generated by generate-rule-indexes.ts\n${allRules
.sort(sonarKeySorter)
.map(id => `export { rule as ${id} } from './${id}/index.js'; // ${eslintIds[id]} \n`)
.join('')}`,
allRulesIndex,
await prettier.format(
`${header}\n\n// DO NOT EDIT! This file was generated by generate-rule-indexes.ts\n${allRules
.sort(sonarKeySorter)
.map(id => `export { rule as ${id} } from './${id}/index.js'; // ${eslintIds[id]}\n`)
.join('')}`,
{ ...prettierOpts, filepath: allRulesIndex },
),
);

//sort once;
pluginRules.sort(sonarKeySorter);

await writeFile(
join(RULES_FOLDER, './plugin-rules.ts'),
`${header}\n\n// DO NOT EDIT! This file was generated by generate-rule-indexes.ts\n
pluginRulesIndex,
await prettier.format(
`${header}\n\n// DO NOT EDIT! This file was generated by generate-rule-indexes.ts\n
${pluginRules.map(id => `import { rule as ${id} } from './${id}/index.js';\n`).join('')}
export const rules = {${pluginRules.map(id => ` "${eslintIds[id]}": ${id},\n`).join('')}};\n`,
export const rules = {\n${pluginRules.map(id => ` '${eslintIds[id]}': ${id},\n`).join('')}};\n`,
{ ...prettierOpts, filepath: allRulesIndex },
),
);

0 comments on commit 1218b8e

Please sign in to comment.