Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump all upgradable deps, fix related usage #321

Merged
merged 4 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"node": "14",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, is there a particular reason for node 14 over latest lts (16)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 14 is LTS now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and remains in active LTS until October of this year.
16 is the next LTS https://github.com/nodejs/Release#release-schedule and will be active LTS until October of next year, giving a bit more time for updates/fixes/support.

"packages": [
"packages/*"
],
Expand Down
13 changes: 0 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,17 @@ module.exports = {
// `strictNullChecks` is required
'@typescript-eslint/no-unnecessary-condition': 0,
},
settings: {
node: {
allowModules: ['@babel/types', 'estree', 'unist'],
},
},
overrides: [
{
files: '*.ts',
rules: {
'@typescript-eslint/consistent-type-imports': 2,
},
},
{
files: '**/*.{md,mdx}/**',
rules: {
'unicorn/filename-case': 0,
},
},
{
files: '*.{md,mdx}',
rules: {
'react/no-unescaped-entities': 1,
// related to https://github.com/eslint/eslint/issues/14207
'unicorn/filename-case': 0,
},
settings: {
'mdx/code-blocks': true,
Expand Down
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@
"typecov": "type-coverage"
},
"devDependencies": {
"@1stg/lib-config": "^1.2.10",
"@1stg/tslint-config": "^1.2.0",
"@types/eslint": "^7.2.10",
"@1stg/lib-config": "^3.0.0",
"@1stg/tslint-config": "^2.0.0",
"@types/eslint": "^7.2.14",
"@types/eslint-plugin-markdown": "^2.0.0",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.41",
"@types/react": "^17.0.4",
"@types/unist": "^2.0.3",
"@types/jest": "^26.0.24",
"@types/node": "^16.3.0",
"@types/react": "^17.0.14",
"@types/unist": "^2.0.5",
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
"lerna": "^4.0.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
"remark-validate-links": "^10.0.4",
"ts-jest": "^26.5.5",
"ts-node": "^9.1.1",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"tslint": "^6.1.3",
"type-coverage": "^2.17.3",
"typescript": "^4.2.4",
"type-coverage": "^2.18.0",
"typescript": "^4.3.5",
"yarn-deduplicate": "^3.1.0"
},
"resolutions": {
"@babel/core": "^7.13.16",
"prettier": "^2.2.1",
"tslib": "^2.2.0"
"@babel/core": "^7.14.6",
"prettier": "^2.3.2",
"tslib": "^2.3.0"
},
"commitlint": {
"extends": [
Expand Down Expand Up @@ -89,6 +89,10 @@
[
2
]
],
[
"validate-links",
true
]
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"remark-mdx": "^1.6.22",
"remark-parse": "^8.0.3",
"tslib": "^2.2.0",
"tslib": "^2.3.0",
"unified": "^9.2.1"
}
}
1 change: 1 addition & 0 deletions packages/eslint-mdx/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const arrayify = <T, R = T extends Array<infer S> ? S : T>(
return arr
}, [])

// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- test coverage
export const first = <T>(items: T[] | readonly T[]) => items && items[0]

export const last = <T>(items: T[] | readonly T[]) =>
Expand Down
20 changes: 11 additions & 9 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { AST, Linter } from 'eslint'
import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import unified from 'unified'
import type { Node, Parent } from 'unist'

import {
arrayify,
Expand All @@ -26,6 +25,8 @@ import { traverse } from './traverse'
import type {
Comment,
LocationError,
Node,
Parent,
ParserFn,
ParserOptions,
ParserServices,
Expand All @@ -47,7 +48,8 @@ export const DEFAULT_PARSER_OPTIONS: ParserOptions = {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: new Date().getUTCFullYear() as Linter.ParserOptions['ecmaVersion'],
ecmaVersion:
new Date().getUTCFullYear() as Linter.ParserOptions['ecmaVersion'],
sourceType: 'module',
tokens: true,
filePath: '__placeholder__.mdx',
Expand Down Expand Up @@ -80,7 +82,7 @@ export class Parser {
}

normalizeJsxNode(node: Node, parent?: Parent, options = this._options) {
const value = node.value as string
const value = node.value

if (node.type !== 'jsx' || isComment(value)) {
return node
Expand Down Expand Up @@ -235,9 +237,9 @@ export class Parser {
}

/* istanbul ignore next */
return ('ast' in program && program.ast
? program
: { ast: program }) as Linter.ESLintParseResult
return (
'ast' in program && program.ast ? program : { ast: program }
) as Linter.ESLintParseResult
}

// fix adjacent JSX nodes
Expand All @@ -247,7 +249,7 @@ export class Parser {
node: Node,
options: ParserOptions,
): Node | Node[] {
const value = node.value as string
const value = node.value

let program: AST.Program

Expand Down Expand Up @@ -281,7 +283,7 @@ export class Parser {
return node
}

const { expression } = (program.body[0] as unknown) as ExpressionStatement
const { expression } = program.body[0] as unknown as ExpressionStatement

if (!isJsxNode(expression) || expression.children.length <= 1) {
return node
Expand Down Expand Up @@ -339,7 +341,7 @@ export class Parser {
this._services.JSXElementsWithHTMLComments.push(node)
}

const value = node.value as string
const value = node.value

const { loc, start, end } = normalizePosition(node.position)

Expand Down
14 changes: 5 additions & 9 deletions packages/eslint-mdx/src/traverse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Node, Parent } from 'unist'

import { arrayify, last } from './helpers'
import { parser } from './parser'
import {
Expand All @@ -9,7 +7,7 @@ import {
isOpenTag,
isSelfClosingTag,
} from './regexp'
import type { TraverseOptions, Traverser } from './types'
import type { Node, Parent, TraverseOptions, Traverser } from './types'

export class Traverse {
code: string
Expand Down Expand Up @@ -52,7 +50,7 @@ export class Traverse {
// eslint-disable-next-line sonarjs/cognitive-complexity
return nodes.reduce<Node[]>((acc, node, index) => {
if (node.type === 'jsx') {
const value = node.value as string
const value = node.value
if (isOpenTag(value)) {
offset++
hasOpenTag = true
Expand Down Expand Up @@ -138,12 +136,10 @@ export class Traverse {
return
}

let children = node.children as Node[]

if (children) {
if ('children' in node) {
const parent = node as Parent
children = node.children = this.combineJsxNodes(children, parent)
for (const child of children) {
parent.children = this.combineJsxNodes(parent.children, parent)
for (const child of parent.children) {
this.traverse(child, parent)
}
}
Expand Down
22 changes: 15 additions & 7 deletions packages/eslint-mdx/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { JSXElement, JSXFragment } from '@babel/types'
import type { AST, Linter } from 'eslint'
import type { Node, Parent, Point } from 'unist'
import type { Node as _Node, Parent as _Parent, Point } from 'unist'
wooorm marked this conversation as resolved.
Show resolved Hide resolved

export interface Node<T = string> extends _Node {
value?: T
}

export interface Parent<T = string> extends _Parent {
children: Array<Node<T>>
}

export type Arrayable<T> = T[] | readonly T[]

Expand All @@ -14,7 +22,7 @@ export declare type ValueOf<T> = T extends {
? N
: never

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

export type ParserFn = (
code: string,
Expand All @@ -23,10 +31,10 @@ export type ParserFn = (

export type ParserConfig =
| {
parseForESLint: ParserFn
parse: ParserFn
}
| {
parse: ParserFn
parseForESLint: ParserFn
}

export interface LocationError {
Expand All @@ -37,10 +45,10 @@ export interface LocationError {
}

export interface ParserOptions extends Linter.ParserOptions {
extensions?: string | string[]
markdownExtensions?: string | string[]
extensions?: string[] | string
markdownExtensions?: string[] | string
filePath?: string
parser?: string | ParserConfig | ParserFn
parser?: ParserConfig | ParserFn | string
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
}

export type Traverser = (node: Node, parent?: Parent) => void
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-mdx/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module 'remark-mdx' {
import type * as unified from 'unified'

const mdx: unified.Attacher
export = mdx
}
6 changes: 3 additions & 3 deletions packages/eslint-plugin-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"dependencies": {
"cosmiconfig": "^7.0.0",
"eslint-mdx": "^1.13.0",
"eslint-plugin-markdown": "^2.1.0",
"eslint-plugin-markdown": "^2.2.0",
"remark-mdx": "^1.6.22",
"remark-parse": "^8.0.3",
"remark-stringify": "^8.1.1",
"synckit": "^0.1.5",
"tslib": "^2.2.0",
"synckit": "^0.2.0",
"tslib": "^2.3.0",
"unified": "^9.2.1",
"vfile": "^4.2.1"
}
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin-mdx/src/configs/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { base } from './base'
let isReactPluginAvailable = false

try {
// eslint-disable-next-line node/no-extraneous-require
require.resolve('eslint-plugin-react')
isReactPluginAvailable = true
} catch {}
Expand Down
6 changes: 2 additions & 4 deletions packages/eslint-plugin-mdx/src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const OVERRIDES_AVAILABLE_VERSION = 6.4
// istanbul ignore else
if (minorVersion >= OVERRIDES_AVAILABLE_VERSION) {
const overrides: Array<{
files: string | string[]
extends?: string | string[]
files: string[] | string
extends?: string[] | string
rules?: Record<string, number | [number, unknown]>
}> = [
{
Expand All @@ -35,9 +35,7 @@ if (minorVersion >= OVERRIDES_AVAILABLE_VERSION) {
},
]
try {
// eslint-disable-next-line node/no-extraneous-require
require.resolve('prettier')
// eslint-disable-next-line node/no-extraneous-require
require.resolve('eslint-plugin-prettier')
overrides.push(
{
Expand Down
6 changes: 4 additions & 2 deletions packages/eslint-plugin-mdx/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
export const getGlobals = <
T extends Record<string, unknown> | string[],
G extends Record<string, boolean>,
R extends G = G & Record<T extends Array<infer R> ? R : keyof T, false>
R extends G = G & Record<T extends Array<infer R> ? R : keyof T, false>,
>(
sources: T,
initialGlobals: G = {} as G,
): R =>
(Array.isArray(sources)
? (sources as string[])
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
(sources as string[])
: Object.keys(sources)
).reduce(
(globals, source) =>
Object.assign(globals, {
[source]: false,
}),
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
initialGlobals as R,
)
2 changes: 1 addition & 1 deletion packages/eslint-plugin-mdx/src/processors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const DEFAULT_LANGUAGE_MAPPER: Record<string, string> = {

export function getShortLang(
filename: string,
languageMapper?: false | Record<string, string>,
languageMapper?: Record<string, string> | false,
): string {
const language = last(filename.split('.'))
if (languageMapper === false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-mdx/src/processors/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const { verify } = ESLinter.prototype
ESLinter.prototype.verify = function (
code: SourceCode | string,
config: LinterConfig,
options?: string | Linter.LintOptions,
options?: Linter.LintOptions | string,
) {
// fetch settings
const settings = ((config &&
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-mdx/src/processors/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface ESLintMdxSettings {
'mdx/code-blocks'?: boolean
'mdx/language-mapper'?: false | Record<string, string>
'mdx/language-mapper'?: Record<string, string> | false
}

export interface ProcessorOptions {
lintCodeBlocks: boolean
languageMapper?: false | Record<string, string>
languageMapper?: Record<string, string> | false
}
1 change: 0 additions & 1 deletion packages/eslint-plugin-mdx/src/rules/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export const getRemarkProcessor = (searchFrom: string, isMdx: boolean) => {
/* istanbul ignore else */
if (plugins.length > 0) {
try {
// eslint-disable-next-line node/no-extraneous-require
plugins.push([require.resolve('remark-lint-file-extension'), false])
} catch {
// just ignore if the package does not exist
Expand Down
Loading