Skip to content

Commit b48311c

Browse files
committed
refactor: apply stricter rules
1 parent ae59913 commit b48311c

File tree

7 files changed

+926
-869
lines changed

7 files changed

+926
-869
lines changed

.eslintrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module.exports = {
1212
root: true,
1313
extends: ['@1stg'],
1414
rules: {
15-
'@typescript-eslint/naming-convention': 0,
15+
// `strictNullChecks` is required
1616
'@typescript-eslint/no-unnecessary-condition': 0,
17-
'@typescript-eslint/no-unsafe-assignment': 0,
18-
'@typescript-eslint/unbound-method': 0, // See https://github.com/typescript-eslint/typescript-eslint/issues/636
1917
},
2018
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
1919
"lint:ts": "tslint -p . -t stylish",
2020
"lint:tsc": "tsc",
21-
"postinstall": "yarn-deduplicate || exit 0",
21+
"postinstall": "yarn-deduplicate --strategy fewer || exit 0",
2222
"prelint": "yarn build:ts",
2323
"prerelease": "yarn build",
2424
"pretest": "yarn clean",
2525
"release": "lerna publish --conventional-commits --create-release github --yes",
26-
"test": "ts-node --skip-ignore node_modules/.bin/jest",
26+
"test": "jest",
2727
"typecov": "type-coverage"
2828
},
2929
"devDependencies": {
30-
"@1stg/lib-config": "^1.1.8",
31-
"@1stg/tslint-config": "^1.0.1",
30+
"@1stg/lib-config": "^1.1.9",
31+
"@1stg/tslint-config": "^1.1.0",
3232
"@types/eslint": "^7.2.6",
3333
"@types/jest": "^26.0.20",
3434
"@types/node": "^14.14.31",
@@ -48,6 +48,7 @@
4848
"yarn-deduplicate": "^3.1.0"
4949
},
5050
"resolutions": {
51+
"@babel/core": "^7.13.8",
5152
"prettier": "^2.2.1",
5253
"tslib": "^2.1.0"
5354
},

packages/eslint-mdx/src/helper.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const isJsxNode = (node: { type: string }): node is JsxNode =>
2727
export const normalizeParser = (parser?: ParserOptions['parser']) => {
2828
if (parser) {
2929
if (typeof parser === 'string') {
30-
// eslint-disable-next-line @typescript-eslint/no-require-imports
31-
parser = require(parser)
30+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
31+
parser = require(parser) as ParserOptions['parser']
3232
}
3333

3434
if (typeof parser === 'object') {
@@ -50,12 +50,14 @@ export const normalizeParser = (parser?: ParserOptions['parser']) => {
5050
for (const fallback of FALLBACK_PARSERS) {
5151
try {
5252
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
53-
const fallbackParser: Linter.ParserModule = require(fallback)
53+
const fallbackParser = require(fallback) as Linter.ParserModule
5454
/* istanbul ignore next */
5555
const parserFn =
5656
'parseForESLint' in fallbackParser
57-
? fallbackParser.parseForESLint
58-
: fallbackParser.parse
57+
? // eslint-disable-next-line @typescript-eslint/unbound-method
58+
fallbackParser.parseForESLint
59+
: // eslint-disable-next-line @typescript-eslint/unbound-method
60+
fallbackParser.parse
5961
/* istanbul ignore else */
6062
if (parserFn) {
6163
parsers.unshift(parserFn)

packages/eslint-mdx/src/parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ export class Parser {
222222
try {
223223
program = parser(code, this._options)
224224
break
225-
} catch (e) {
225+
} catch (err) {
226226
if (!parseError) {
227-
parseError = e as Error
227+
parseError = err as Error
228228
}
229229
}
230230
}
@@ -387,4 +387,5 @@ export class Parser {
387387

388388
export const parser = new Parser()
389389

390+
// eslint-disable-next-line @typescript-eslint/unbound-method
390391
export const { parse, parseForESLint } = parser

packages/eslint-plugin-mdx/src/configs/overrides.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { getGlobals } from './helper'
44
let rebass: typeof import('rebass') | string[]
55

66
try {
7-
// eslint-disable-next-line @typescript-eslint/no-require-imports
8-
rebass = require('rebass')
7+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
8+
rebass = require('rebass') as typeof rebass
99
} catch {
1010
// `rebass`(or `reflexbox` actually) requires `react` as peerDependency, but not all projects using `mdx` are `React` based, so we fallback to hardcoded `rebass` Components here
1111
/* istanbul ignore next */

packages/eslint-plugin-mdx/src/rules/helper.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export const requirePkg = <T>(
2727
let error: Error
2828
for (const pkg of packages) {
2929
try {
30-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return
31-
return require(pkg)
30+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
31+
return require(pkg) as T
3232
} catch (err) {
3333
if (!error) {
34-
error = err
34+
error = err as Error
3535
}
3636
}
3737
}
@@ -53,10 +53,10 @@ export const getRemarkProcessor = (searchFrom: string, isMdx: boolean) => {
5353
}
5454

5555
/* istanbul ignore next */
56-
const { config, filepath }: Partial<CosmiconfigResult> =
57-
searchSync(searchFrom) || {}
56+
const result: Partial<CosmiconfigResult> = searchSync(searchFrom) || {}
5857
/* istanbul ignore next */
59-
const { plugins = [], settings }: Partial<RemarkConfig> = config || {}
58+
const { plugins = [], settings } = (result.config ||
59+
{}) as Partial<RemarkConfig>
6060

6161
try {
6262
// disable this rule automatically since we already have a parser option `extensions`
@@ -80,7 +80,7 @@ export const getRemarkProcessor = (searchFrom: string, isMdx: boolean) => {
8080
return processor.use(
8181
/* istanbul ignore next */
8282
typeof plugin === 'string'
83-
? requirePkg(plugin, 'remark', filepath)
83+
? requirePkg(plugin, 'remark', result.filepath)
8484
: plugin,
8585
...pluginSettings,
8686
)

0 commit comments

Comments
 (0)