Skip to content

Commit

Permalink
refactor: use union @1stg/lib-config to simplify devDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Nov 3, 2019
1 parent 86a73a8 commit 96fc83a
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 558 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ tsNode.register({
module.exports = {
root: true,
extends: ['@1stg/eslint-config/recommended'],
settings: {
node: {
allowModules: ['@babel/types', 'estree', 'unist'],
},
},
rules: {
'@typescript-eslint/no-unnecessary-condition': 0,
'@typescript-eslint/unbound-method': 0, // See https://github.com/typescript-eslint/typescript-eslint/issues/636
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.log
*.tsbuildinfo
.*cache
.changelog
.type-coverage
coverage
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ before_deploy:
- cp -f README.md packages/eslint-mdx
- cp -f README.md packages/eslint-plugin-mdx
- 'git add --all && git commit -m "docs: update README" || echo "nothing changed to commit"'
- yarn lerna-changelog
- yarn global add lerna-changelog
- lerna-changelog

deploy:
- provider: script
Expand Down
30 changes: 7 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,28 @@
"type-coverage": "type-coverage --cache --detail --ignore-catch --ignore-files *.d.ts --strict"
},
"devDependencies": {
"@1stg/babel-preset": "^0.7.10",
"@1stg/commitlint-config": "^0.1.2",
"@1stg/eslint-config": "^0.13.2",
"@1stg/husky-config": "^0.3.2",
"@1stg/lint-staged": "^0.8.11",
"@1stg/prettier-config": "^0.4.3",
"@1stg/remark-config": "^0.2.2",
"@1stg/tsconfig": "^0.6.1",
"@1stg/tslint-config": "^0.4.4",
"@babel/core": "^7.6.4",
"@commitlint/cli": "^8.2.0",
"@pkgr/rollup": "^0.3.0",
"@1stg/lib-config": "^0.1.6",
"@1stg/tslint-config": "^0.5.5",
"@types/cosmiconfig": "^5.0.3",
"@types/eslint": "^6.1.2",
"@types/jest": "^24.0.19",
"@types/node": "^12.11.5",
"@types/react": "^16.9.9",
"@types/eslint": "^6.1.3",
"@types/jest": "^24.0.21",
"@types/node": "^12.12.5",
"@types/react": "^16.9.11",
"@types/rebass": "^4.0.3",
"@types/unist": "^2.0.3",
"eslint": "^6.5.1",
"eslint-mdx": "link:packages/eslint-mdx/src",
"eslint-plugin-mdx": "link:packages/eslint-plugin-mdx/src",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lerna": "^3.18.3",
"lerna-changelog": "^0.8.2",
"lint-staged": "^9.4.2",
"npm-run-all": "^4.1.5",
"prettier": "1.18.2",
"react": "^16.11.0",
"rollup": "^1.25.1",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"type-coverage": "^2.3.0",
"typescript": "^3.6.4"
},
"resolutions": {
"@babel/core": "^7.6.4",
"typescript": "^3.6.4"
},
"commitlint": {
Expand Down
7 changes: 3 additions & 4 deletions packages/eslint-mdx/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import { AST, Linter } from 'eslint'
import { parse as esParse } from 'espree'
import { SourceLocation } from 'estree'
import { Position } from 'unist'

import {
Arrayable,
Expand All @@ -24,6 +22,7 @@ export const JSX_TYPES: JsxTypes = ['JSXElement', 'JSXFragment']
export const isJsxNode = (node: { type: string }): node is JsxNode =>
JSX_TYPES.includes(node.type as JsxType)

// eslint-disable-next-line sonarjs/cognitive-complexity
export const normalizeParser = (parser?: ParserOptions['parser']) => {
if (parser) {
if (typeof parser === 'string') {
Expand Down Expand Up @@ -68,7 +67,7 @@ export const normalizeParser = (parser?: ParserOptions['parser']) => {
}

export const normalizePosition = (
position: Position,
position: import('unist').Position,
): Pick<AST.Program, 'loc' | 'range'> & {
start: number
end: number
Expand All @@ -87,7 +86,7 @@ export const normalizePosition = (

export interface BaseNode {
type: string
loc?: SourceLocation
loc?: import('estree').SourceLocation
range?: [number, number]
}

Expand Down
18 changes: 13 additions & 5 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { AST, Linter } from 'eslint'
import { ExpressionStatement } from 'estree'
import path from 'path'

import { AST, Linter } from 'eslint'
import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import unified from 'unified'
import { Node, Parent } from 'unist'

import {
hasProperties,
Expand All @@ -16,7 +15,14 @@ import {
} from './helper'
import { COMMENT_CONTENT_REGEX, isComment } from './regexp'
import { traverse } from './traverse'
import { Comment, LocationError, ParserFn, ParserOptions } from './types'
import {
Comment,
LocationError,
Node,
Parent,
ParserFn,
ParserOptions,
} from './types'

export const mdxProcessor = unified()
.use(remarkParse)
Expand Down Expand Up @@ -225,6 +231,7 @@ export class Parser {

// fix adjacent JSX nodes
// @internal
// eslint-disable-next-line sonarjs/cognitive-complexity
private _normalizeJsxNodes(
node: Node,
options: ParserOptions,
Expand Down Expand Up @@ -257,7 +264,8 @@ export class Parser {
return node
}

const { expression } = program.body[0] as ExpressionStatement
const { expression } = program
.body[0] as import('estree').ExpressionStatement

if (!isJsxNode(expression) || expression.children.length <= 1) {
return node
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-mdx/src/traverse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Node, Parent } from 'unist'

import { last } from './helper'
import {
isCloseTag,
Expand All @@ -8,7 +6,7 @@ import {
isOpenTag,
isSelfClosingTag,
} from './regexp'
import { TraverseOptions, Traverser } from './types'
import { Node, Parent, TraverseOptions, Traverser } from './types'

export class Traverse {
// @internal
Expand All @@ -35,6 +33,7 @@ export class Traverse {
let offset = 0
const jsxNodes: Node[] = []
const { length } = nodes
// eslint-disable-next-line sonarjs/cognitive-complexity
return nodes.reduce<Node[]>((acc, node, index) => {
if (node.type === 'jsx') {
const value = node.value as string
Expand Down
12 changes: 7 additions & 5 deletions packages/eslint-mdx/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { JSXElement, JSXFragment } from '@babel/types'
/* eslint-disable @typescript-eslint/no-type-alias */
import { AST, Linter } from 'eslint'
import { Node, Parent, Point } from 'unist'

export type JSXElement = import('@babel/types').JSXElement
export type JSXFragment = import('@babel/types').JSXFragment
export type Node = import('unist').Node
export type Parent = import('unist').Parent
export type Point = import('unist').Point

export type JsxNode = (JSXElement | JSXFragment) & { range: [number, number] }

// eslint-disable-next-line @typescript-eslint/no-type-alias
export type JsxTypes = Readonly<[JSXElement['type'], JSXFragment['type']]>

// eslint-disable-next-line @typescript-eslint/no-type-alias
export type JsxType = JsxTypes[number]

// eslint-disable-next-line @typescript-eslint/no-type-alias
export type Arrayable<T> = T[] | readonly T[]

export type ParserFn = (
Expand Down
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,6 +40,6 @@
"vfile": "^4.0.1"
},
"optionalDependencies": {
"rebass": "^4.0.6"
"rebass": "^4.0.7"
}
}
3 changes: 2 additions & 1 deletion packages/eslint-plugin-mdx/src/rules/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cosmiconfig, { CosmiconfigResult, Explorer } from 'cosmiconfig'
import path from 'path'

import cosmiconfig, { CosmiconfigResult, Explorer } from 'cosmiconfig'
import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-mdx/src/rules/no-jsx-html-comments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Rule } from 'eslint'
import { Comment, JSX_TYPES, JsxType } from 'eslint-mdx'
import { Node } from 'unist'

import { ExpressionStatementWithParent } from './types'

Expand All @@ -21,7 +20,7 @@ export const noJsxHtmlComments: Rule.RuleModule = {
create(context) {
return {
ExpressionStatement(node: ExpressionStatementWithParent) {
const invalidNodes: Node[] =
const invalidNodes: Array<import('unist').Node> =
context.parserServices.JSXElementsWithHTMLComments

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const noUnescapedEntities: Rule.RuleModule = {
const configuration = context.options[0] || {}
const entities: EscapeEntity[] = configuration.forbid || DEFAULTS
return {
// eslint-disable-next-line sonarjs/cognitive-complexity
[EXPRESSION](node: NodeWithParent) {
let { parent } = node

Expand Down Expand Up @@ -108,7 +109,7 @@ export const noUnescapedEntities: Rule.RuleModule = {
message: `\`${
entity.char
}\` can be escaped with ${entity.alternatives
.map(alt => `\`${alt}\``)
.map(alt => '``'.split('').join(alt))
.join(', ')}.`,
node,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-mdx/src/rules/remark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'

import { Rule } from 'eslint'
import { DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS } from 'eslint-mdx'
import path from 'path'
import vfile from 'vfile'

import { getRemarkProcessor } from './helper'
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-mdx/src/rules/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line node/no-extraneous-import
import { ExpressionStatement, Node } from 'estree'
import { Attacher } from 'unified'

Expand Down
5 changes: 3 additions & 2 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CLIEngine } from 'eslint'
import { basename } from 'path'

export const cli = new CLIEngine({
import { CLIEngine } from 'eslint'

const cli = new CLIEngine({
ignore: false,
fix: true,
})
Expand Down
3 changes: 2 additions & 1 deletion test/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getGlobals, requirePkg } from 'eslint-plugin-mdx'
import path from 'path'

import { getGlobals, requirePkg } from 'eslint-plugin-mdx'

describe('Helpers', () => {
it('should resolve globals correctly', () => {
expect(getGlobals({})).toEqual({})
Expand Down
Loading

0 comments on commit 96fc83a

Please sign in to comment.