Skip to content

Commit 9f6b2b7

Browse files
authored
Add TS lint testing and @typescript-eslint/explicit-module-boundary-types warning (#24)
We want to use @typescript-eslint/explicit-module-boundary-types and will have it as a warning for now to not disrupt us as much. Later on we will make it an error. This is the first TS rule we are adding in this configuration, therefore, the ts eslint config and a ts file for testing local eslint issues are now part of testing.
1 parent 75610f0 commit 9f6b2b7

7 files changed

+3683
-19
lines changed

demo/example.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function someFunc({ prop1 }) {
2+
console.log({ prop1 })
3+
}
4+
5+
export function someFunc2(prop1): void {}
6+
7+
const unusedVar = 3
8+
9+
type UnusedType = number

demo/test/linting-config.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ test('Should apply our custom linting rules consistently', async (t) => {
2525
test('Should apply a consistent overall eslint configuration', async (t) => {
2626
return processFile(t, 'local-linting-final-config.json') // If this fails, go cry to mommy
2727
})
28+
29+
test('Should apply a consistent overall eslint configuration for TS', async (t) => {
30+
return processFile(t, 'local-linting-final-config-ts.json') // If this fails, go cry to mommy
31+
})

demo/test/snapshots/format-config.js

+27-14
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,38 @@
55
/* eslint no-console: "off" -- node scripts use the console, so disable for the whole file */
66

77
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')
910

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+
}
1632
)
1733

34+
const finalTsConfigName = 'local-linting-final-config-ts'
1835
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),
2538
(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)
2740
}
2841
)
2942

0 commit comments

Comments
 (0)