Skip to content

Commit

Permalink
chore: improve type coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Feb 28, 2021
1 parent 43e448b commit ae59913
Show file tree
Hide file tree
Showing 11 changed files with 732 additions and 613 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ deploy:
branch: develop

after_script:
- yarn add -D @codechecks/client @codechecks/build-size-watcher @codechecks/type-coverage-watcher -W
- yarn add -D @codechecks/client @codechecks/build-size-watcher typecov -W
- yarn codechecks
3 changes: 2 additions & 1 deletion codechecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ checks:
name: 'eslint-plugin-mdx pkg size'
files:
- path: 'packages/eslint-plugin-mdx/lib/**/*.*'
- name: type-coverage-watcher
- name: typecov
options:
atLeast: 99
ignoreAsAssertion: true
ignoreCatch: true
ignoreFiles:
- '*.d.ts'
Expand Down
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@
"pretest": "yarn clean",
"release": "lerna publish --conventional-commits --create-release github --yes",
"test": "ts-node --skip-ignore node_modules/.bin/jest",
"type-coverage": "type-coverage --cache --detail --ignore-catch --ignore-files '**/*.d.ts' --strict --update"
"typecov": "type-coverage"
},
"devDependencies": {
"@1stg/lib-config": "^1.0.5",
"@1stg/tslint-config": "^1.0.0",
"@1stg/lib-config": "^1.1.8",
"@1stg/tslint-config": "^1.0.1",
"@types/eslint": "^7.2.6",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/react": "^17.0.2",
"@types/rebass": "^4.0.7",
"@types/rebass": "^4.0.8",
"@types/unist": "^2.0.3",
"eslint-mdx": "link:packages/eslint-mdx/src",
"eslint-plugin-mdx": "link:packages/eslint-plugin-mdx/src",
"lerna": "^3.22.1",
"npm-run-all": "^4.1.5",
"react": "^17.0.1",
"ts-jest": "^26.5.1",
"ts-jest": "^26.5.2",
"ts-node": "^9.1.1",
"tslint": "^6.1.3",
"type-coverage": "^2.15.1",
"typescript": "^4.3.0-dev.20210220",
"type-coverage": "^2.16.3",
"typescript": "^4.2.2",
"yarn-deduplicate": "^3.1.0"
},
"resolutions": {
Expand Down Expand Up @@ -87,6 +87,15 @@
]
},
"typeCoverage": {
"atLeast": 97.96
"atLeast": 99.37,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
"ignoreCatch": true,
"ignoreFiles": [
"**/*.d.ts"
],
"strict": true,
"update": true
}
}
2 changes: 1 addition & 1 deletion packages/eslint-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"remark-mdx": "^1.6.22",
"remark-parse": "^8.0.3",
"tslib": "^2.1.0",
"unified": "^9.1.0"
"unified": "^9.2.1"
}
}
5 changes: 2 additions & 3 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Parent,
ParserFn,
ParserOptions,
ParserServices,
} from './types'

export const mdProcessor = unified().use(remarkParse).freeze()
Expand Down Expand Up @@ -66,9 +67,7 @@ export class Parser {
private _ast: AST.Program

// @internal
private _services: {
JSXElementsWithHTMLComments: Node[]
}
private _services: ParserServices

// @internal
private readonly _options = DEFAULT_PARSER_OPTIONS
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-mdx/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ export interface Comment {
}
origin: string
}

export interface ParserServices {
JSXElementsWithHTMLComments: Node[]
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"remark-parse": "^8.0.3",
"remark-stringify": "^8.1.1",
"tslib": "^2.1.0",
"unified": "^9.1.0",
"unified": "^9.2.1",
"vfile": "^4.2.1"
},
"optionalDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions packages/eslint-plugin-mdx/src/rules/no-jsx-html-comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Rule } from 'eslint'
import { Comment, JSX_TYPES, JsxType } from 'eslint-mdx'
import { Comment, JSX_TYPES, JsxType, ParserServices } from 'eslint-mdx'

import { ExpressionStatementWithParent } from './types'

Expand All @@ -19,9 +19,8 @@ export const noJsxHtmlComments: Rule.RuleModule = {
create(context) {
return {
ExpressionStatement(node: ExpressionStatementWithParent) {
const invalidNodes: Array<import('unist').Node> =
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
context.parserServices.JSXElementsWithHTMLComments
const invalidNodes = (context.parserServices as ParserServices)
.JSXElementsWithHTMLComments

if (
!JSX_TYPES.includes(node.expression.type as JsxType) ||
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-mdx/src/rules/no-unescaped-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const EXPRESSION = 'Literal, JSXText'
export const noUnescapedEntities: Rule.RuleModule = {
...reactNoUnescapedEntities,
create(context) {
const configuration: {
const configuration = (context.options[0] || {}) as {
forbid?: EscapeEntity[]
} = context.options[0] || {}
}
const entities = configuration.forbid || DEFAULTS
return {
// eslint-disable-next-line sonarjs/cognitive-complexity
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin-mdx/src/rules/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export const remark: Rule.RuleModule = {
const filename = context.getFilename()
const extname = path.extname(filename)
const sourceCode = context.getSourceCode()
const options = context.parserOptions
const options = context.parserOptions as {
extensions: string[]
markdownExtensions: string[]
}
const isMdx = DEFAULT_EXTENSIONS.concat(options.extensions || []).includes(
extname,
)
Expand Down
Loading

0 comments on commit ae59913

Please sign in to comment.