Skip to content
Permalink
Browse files

chore(release): 0.5.0

  • Loading branch information
JounQin committed Jul 31, 2019
2 parents 57f5595 + 5d62b55 commit 39231aa31be4e018b030eac028f357f9f68a5024
Showing with 78 additions and 23 deletions.
  1. +0 −6 .eslintrc.js
  2. +8 −9 CHANGELOG.md
  3. +4 −5 README.md
  4. +10 −1 package.json
  5. +3 −0 src/index.ts
  6. +7 −2 src/parser.ts
  7. +5 −0 src/rules/index.ts
  8. +34 −0 src/rules/no-unused-expressions.ts
  9. +1 −0 tsconfig.json
  10. +6 −0 types.d.ts
@@ -28,12 +28,6 @@ module.exports = {
{
files: ['*.mdx'],
extends: ['plugin:@rxts/mdx/recommended'],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'no-unused-expressions': 0,
},
},
{
files: ['*.ts', '*.tsx'],
@@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.4.1](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.4.0...v0.4.1) (2019-07-31)


### Features

* perf: extract `parseMdx`, exports everything in package ([1f965a1](https://github.com/rx-ts/eslint-plugin-mdx/commit/1f965a1))

## [0.4.0](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.3.1...v0.4.0) (2019-07-31)


@@ -14,7 +21,7 @@ All notable changes to this project will be documented in this file. See [standa

### Bug Fixes

* .* could not match multi lines, use [\s\S]* instead, close [#4](https://github.com/rx-ts/eslint-plugin-mdx/issues/4) ([f7e7efe](https://github.com/rx-ts/eslint-plugin-mdx/commit/f7e7efe))
* `.*` could not match multi lines, use `[\s\S]*` instead, close [#4](https://github.com/rx-ts/eslint-plugin-mdx/issues/4) ([f7e7efe](https://github.com/rx-ts/eslint-plugin-mdx/commit/f7e7efe))

## [0.3.0](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.2.1...v0.3.0) (2019-07-30)

@@ -37,35 +44,27 @@ All notable changes to this project will be documented in this file. See [standa

* support custom parser like babel-eslint ([b718574](https://github.com/rx-ts/eslint-plugin-mdx/commit/b718574))



### [0.1.3](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.1.2...v0.1.3) (2019-07-29)


### Bug Fixes

* upgrade peer dependency eslint to >= 6.0.0 ([#3](https://github.com/rx-ts/eslint-plugin-mdx/issues/3) [#4](https://github.com/rx-ts/eslint-plugin-mdx/issues/4)) ([f0ab288](https://github.com/rx-ts/eslint-plugin-mdx/commit/f0ab288))



### [0.1.2](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.1.1...v0.1.2) (2019-07-29)


### Bug Fixes

* show correct column and line on lint error ([90c5390](https://github.com/rx-ts/eslint-plugin-mdx/commit/90c5390))



### [0.1.1](https://github.com/rx-ts/eslint-plugin-mdx/compare/v0.1.0...v0.1.1) (2019-07-29)


### Bug Fixes

* overrides in node_modules seems not working ([d2f1535](https://github.com/rx-ts/eslint-plugin-mdx/commit/d2f1535))



## 0.1.0 (2019-07-29)


@@ -57,6 +57,8 @@ npm i -D @rxts/eslint-plugin-mdx
"parser": "@rxts/eslint-plugin-mdx",
"plugins": ["@rxts/mdx"],
"rules": {
"@rxts/mdx/no-unused-expressions": 2,
"no-unused-expressions": 0,
"react/react-in-jsx-scope": 0
}
}
@@ -86,12 +88,9 @@ npm i -D @rxts/eslint-plugin-mdx
}
```

## Limitations
## Limitation

1. This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint](https://github.com/markdownlint/markdownlint) to lint that part.

2. `MDX` can render `jsx` block automatically without exporting them, but `eslint` will report `no-unused-expressions` issue which could be unexpected, so you may need to disable this rule for `*.mdx`.
I'm not going to disable this rule in the recommended config, because I'm going to add a custom `mdx/no-unused-expressions` rule to replace the incompatible one, which should not affect the `jsx` codes.
> This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint](https://github.com/markdownlint/markdownlint) to lint that part.
## Changelog

@@ -1,6 +1,6 @@
{
"name": "@rxts/eslint-plugin-mdx",
"version": "0.4.1",
"version": "0.5.0",
"description": "ESLint Parser/Plugin for MDX",
"repository": "git@github.com:rx-ts/eslint-plugin-mdx.git",
"author": "JounQin <admin@1stg.me>",
@@ -16,6 +16,15 @@
"test": "jest",
"lint": "eslint . --ext js,mdx,ts,tsx"
},
"keywords": [
"eslint",
"eslint-parser",
"eslint-plugin",
"eslint-parser-mdx",
"eslint-plugin-mdx",
"mdx",
"eslint-mdx"
],
"peerDependencies": {
"eslint": ">=5.0.0"
},
@@ -3,13 +3,16 @@ import path from 'path'
export * from './helper'
export * from './parser'
export * from './regexp'
export * from './rules'
export * from './traverse'

export const configs = {
recommended: {
parser: path.resolve(__dirname, 'parser'),
plugins: ['@rxts/mdx'],
rules: {
'@rxts/mdx/no-unused-expressions': 2,
'no-unused-expressions': 0,
'react/react-in-jsx-scope': 0,
},
},
@@ -27,7 +27,7 @@ export const parseMdx = unified()

export const parseForESLint = (
code: string,
options: Linter.ParserOptions,
options: Linter.ParserOptions = {},
): Linter.ESLintParseResult => {
let { parser } = options

@@ -45,7 +45,12 @@ export const parseForESLint = (
}
}
} else {
parser = esParse
try {
// try to load babel-eslint automatically
parser = require(require.resolve('babel-eslint')).parse
} catch (e) {
parser = esParse
}
}

const root = parseMdx(code) as Parent
@@ -0,0 +1,5 @@
import { noUnUsedExpressions } from './no-unused-expressions'

export const rules = {
'no-unused-expressions': noUnUsedExpressions,
}
@@ -0,0 +1,34 @@
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
/// <reference path="../../types.d.ts" />

import ESLintNoUnUsedExpressions from 'eslint/lib/rules/no-unused-expressions'

import { Rule } from 'eslint'
import { ExpressionStatement, Node } from 'estree'

export const JSX_TYPES = ['JSXElement', 'JSXFragment'] as const

export type JsxType = (typeof JSX_TYPES)[number]

export interface ExpressionStatementWithParent extends ExpressionStatement {
parent?: {
type: Node['type']
}
}

export const noUnUsedExpressions: Rule.RuleModule = {
create(context) {
const esLintRuleListener = ESLintNoUnUsedExpressions.create(context)
return {
ExpressionStatement(node: ExpressionStatementWithParent) {
if (
JSX_TYPES.includes(node.expression.type as JsxType) &&
node.parent.type === 'Program'
) {
return
}
esLintRuleListener.ExpressionStatement(node)
},
}
},
}
@@ -11,6 +11,7 @@
"outDir": "dist",
"sourceMap": true,
"strict": true,
"strictFunctionTypes": false,
"strictNullChecks": false,
"target": "es5"
}
@@ -4,6 +4,12 @@ declare interface SyntaxError {
lineNumber?: number
}

declare module 'eslint/lib/rules/no-unused-expressions' {
import { Rule } from 'eslint'
const noUnUsedExpressions: Rule.RuleModule
export = noUnUsedExpressions
}

declare module 'espree' {
import * as estree from 'estree'

0 comments on commit 39231aa

Please sign in to comment.
You can’t perform that action at this time.