Skip to content

Commit

Permalink
feat(eslint): 新规则: no-jsx-in-props
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed May 24, 2018
1 parent 58eea58 commit 28c38f4
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
37 changes: 37 additions & 0 deletions packages/eslint-plugin-taro/components.js
@@ -0,0 +1,37 @@
// eslint-disable-next-line
export const DEFAULT_Components_SET = new Set([
'View',
'ScrollView',
'Swiper',
'MovableView',
'CoverView',
'Icon',
'Text',
'RichText',
'Progress',
'Button',
'Checkbox',
'Form',
'Input',
'Label',
'Picker',
'PickerView',
'Radio',
'RadioGroup',
'CheckboxGroup',
'Slider',
'Switch',
'Textarea',
'Navigator',
'Audio',
'Image',
'Video',
'Camera',
'LivePlayer',
'LivePusher',
'Map',
'Canvas',
'OpenData',
'WebView',
'SwiperItem'
])
11 changes: 7 additions & 4 deletions packages/eslint-plugin-taro/package.json
Expand Up @@ -26,11 +26,14 @@
"peerDependencies": {
"eslint": "^4.15.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-standard": "11.0.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0"
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-standard": "11.0.0"
},
"author": "O2Team",
"license": "MIT"
"license": "MIT",
"dependencies": {
"jsx-ast-utils": "^2.0.1"
}
}
24 changes: 24 additions & 0 deletions packages/eslint-plugin-taro/rules/custom/no-jsx-in-props.js
@@ -0,0 +1,24 @@
const { buildDocsMeta } = require('../../utils/utils')

const ERROR_MESSAGE = '不允许在 JSX 参数(props)中传入 JSX 元素'

module.exports = {
meta: {
docs: buildDocsMeta(ERROR_MESSAGE, 'no-jsx-in-props')
},

create (context) {
return {
JSXElement (node) {
const parents = context.getAncestors(node)
const jsxAttr = parents.find(p => p.type === 'JSXAttribute')
if (jsxAttr) {
context.report({
message: ERROR_MESSAGE,
node: jsxAttr
})
}
}
}
}
}
17 changes: 17 additions & 0 deletions packages/eslint-plugin-taro/utils/utils.js
@@ -0,0 +1,17 @@
function docsUrl (rule) {
return 'https://github.com/NervJS/taro/tree/master/packages/eslint-plugin-taro/docs/' + rule + '.md'
}

function buildDocsMeta (description, rule) {
return {
description: '[Taro] ' + description,
category: 'Taro',
recommended: true,
url: docsUrl(rule)
}
}

module.exports = {
docsUrl,
buildDocsMeta
}

0 comments on commit 28c38f4

Please sign in to comment.