|
5 | 5 | /* eslint no-console: "off" -- node scripts use the console, so disable for the whole file */
|
6 | 6 |
|
7 | 7 | const FS = require('fs')
|
8 |
| -const finalConfig = require('./local-linting-final-config.json') |
| 8 | +const finalJsConfig = require('./local-linting-final-config.json') |
| 9 | +const finalTsConfig = require('./local-linting-final-config-ts.json') |
9 | 10 |
|
10 |
| -const formattedRules = Object.fromEntries( |
11 |
| - Object.entries(finalConfig?.rules ?? {}).sort(([ruleNameA], [ruleNameB]) => { |
12 |
| - if (ruleNameA > ruleNameB) return 1 |
13 |
| - if (ruleNameB > ruleNameA) return -1 |
14 |
| - return 0 |
15 |
| - }) |
| 11 | +const parseConfig = (config) => { |
| 12 | + return { |
| 13 | + ...config, |
| 14 | + rules: Object.fromEntries( |
| 15 | + Object.entries(config?.rules ?? {}).sort(([ruleNameA], [ruleNameB]) => { |
| 16 | + if (ruleNameA > ruleNameB) return 1 |
| 17 | + if (ruleNameB > ruleNameA) return -1 |
| 18 | + return 0 |
| 19 | + }) |
| 20 | + ), |
| 21 | + parser: config?.parser?.split('node_modules')[1], |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +const finalJsConfigName = 'local-linting-final-config' |
| 26 | +FS.writeFile( |
| 27 | + `./demo/test/snapshots/${finalJsConfigName}.json`, |
| 28 | + JSON.stringify(parseConfig(finalJsConfig), null, 2), |
| 29 | + (err) => { |
| 30 | + if (err) console.log(`There was an error writing to ${finalJsConfigName}.json file:`, err) |
| 31 | + } |
16 | 32 | )
|
17 | 33 |
|
| 34 | +const finalTsConfigName = 'local-linting-final-config-ts' |
18 | 35 | FS.writeFile(
|
19 |
| - './demo/test/snapshots/local-linting-final-config.json', |
20 |
| - JSON.stringify( |
21 |
| - { ...finalConfig, rules: formattedRules, parser: finalConfig.parser?.split('eslint-config-tree')[1] }, |
22 |
| - null, |
23 |
| - 2 |
24 |
| - ), |
| 36 | + `./demo/test/snapshots/${finalTsConfigName}.json`, |
| 37 | + JSON.stringify(parseConfig(finalTsConfig), null, 2), |
25 | 38 | (err) => {
|
26 |
| - if (err) console.log('There was an error writing to local-linting-final-config.json file:', err) |
| 39 | + if (err) console.log(`There was an error writing to ${finalTsConfigName}.json file:`, err) |
27 | 40 | }
|
28 | 41 | )
|
29 | 42 |
|
|
0 commit comments