From 1b5743f5fc7f1879e3f4a15938ec4c70bb2e6e09 Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Mon, 8 May 2017 22:13:59 +0200 Subject: [PATCH] Update tests to pass parserOptions globally --- tests/lib/rules/display-name.js | 43 +-- tests/lib/rules/forbid-component-props.js | 33 +-- tests/lib/rules/forbid-elements.js | 60 +--- tests/lib/rules/forbid-foreign-prop-types.js | 39 +-- tests/lib/rules/forbid-prop-types.js | 49 +-- tests/lib/rules/jsx-boolean-value.js | 20 +- .../lib/rules/jsx-closing-bracket-location.js | 279 +++++------------- tests/lib/rules/jsx-curly-spacing.js | 223 +++++--------- tests/lib/rules/jsx-equals-spacing.js | 60 ++-- tests/lib/rules/jsx-filename-extension.js | 17 +- tests/lib/rules/jsx-first-prop-new-line.js | 57 ++-- tests/lib/rules/jsx-handler-names.js | 44 +-- tests/lib/rules/jsx-indent-props.js | 25 +- tests/lib/rules/jsx-indent.js | 146 +++------ tests/lib/rules/jsx-key.js | 46 ++- tests/lib/rules/jsx-max-props-per-line.js | 72 ++--- tests/lib/rules/jsx-no-bind.js | 11 +- tests/lib/rules/jsx-no-comment-textnodes.js | 27 +- tests/lib/rules/jsx-no-duplicate-props.js | 42 +-- tests/lib/rules/jsx-no-literals.js | 26 +- tests/lib/rules/jsx-no-target-blank.js | 32 +- tests/lib/rules/jsx-no-undef.js | 51 ++-- tests/lib/rules/jsx-pascal-case.js | 47 +-- tests/lib/rules/jsx-sort-props.js | 126 ++++---- tests/lib/rules/jsx-space-before-closing.js | 50 +--- tests/lib/rules/jsx-tag-spacing.js | 8 +- tests/lib/rules/jsx-uses-react.js | 20 +- tests/lib/rules/jsx-uses-vars.js | 69 ++--- tests/lib/rules/jsx-wrap-multilines.js | 69 ++--- tests/lib/rules/no-array-index-key.js | 127 +++----- tests/lib/rules/no-children-prop.js | 158 ++++------ tests/lib/rules/no-danger-with-children.js | 81 ++--- tests/lib/rules/no-danger.js | 15 +- tests/lib/rules/no-deprecated.js | 11 +- tests/lib/rules/no-did-mount-set-state.js | 26 +- tests/lib/rules/no-did-update-set-state.js | 26 +- tests/lib/rules/no-direct-mutation-state.js | 23 +- tests/lib/rules/no-find-dom-node.js | 21 +- tests/lib/rules/no-is-mounted.js | 18 +- tests/lib/rules/no-multi-comp.js | 19 +- tests/lib/rules/no-render-return-value.js | 22 +- tests/lib/rules/no-set-state.js | 18 +- tests/lib/rules/no-string-refs.js | 32 +- tests/lib/rules/no-unescaped-entities.js | 26 +- tests/lib/rules/no-unknown-property.js | 58 ++-- tests/lib/rules/no-unused-prop-types.js | 249 +++++----------- tests/lib/rules/no-will-update-set-state.js | 26 +- tests/lib/rules/prefer-es6-class.js | 23 +- tests/lib/rules/prefer-stateless-function.js | 42 +-- tests/lib/rules/prop-types.js | 231 ++++----------- tests/lib/rules/react-in-jsx-scope.js | 37 +-- tests/lib/rules/require-default-props.js | 9 +- tests/lib/rules/require-optimization.js | 70 ++--- tests/lib/rules/require-render-return.js | 46 +-- tests/lib/rules/self-closing-comp.js | 71 ++--- tests/lib/rules/sort-comp.js | 38 +-- tests/lib/rules/sort-prop-types.js | 70 ++--- tests/lib/rules/style-prop-object.js | 101 +++---- .../rules/void-dom-elements-no-children.js | 65 ++-- 59 files changed, 1240 insertions(+), 2310 deletions(-) diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index 253854022f..f11a005665 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -14,7 +14,8 @@ var RuleTester = require('eslint').RuleTester; require('babel-eslint'); var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -25,7 +26,7 @@ var parserOptions = { // Tests // ------------------------------------------------------------------------------ -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('display-name', rule, { valid: [{ @@ -39,8 +40,7 @@ ruleTester.run('display-name', rule, { ].join('\n'), options: [{ ignoreTranspilerName: true - }], - parserOptions: parserOptions + }] }, { code: [ 'var Hello = React.createClass({', @@ -57,8 +57,7 @@ ruleTester.run('display-name', rule, { react: { createClass: 'createClass' } - }, - parserOptions: parserOptions + } }, { code: [ 'class Hello extends React.Component {', @@ -70,8 +69,7 @@ ruleTester.run('display-name', rule, { ].join('\n'), options: [{ ignoreTranspilerName: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class Hello {', @@ -79,8 +77,7 @@ ruleTester.run('display-name', rule, { ' return \'Hello World\';', ' }', '}' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'class Hello extends Greetings {', @@ -97,8 +94,7 @@ ruleTester.run('display-name', rule, { ' method;', '}' ].join('\n'), - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ 'class Hello extends React.Component {', @@ -112,8 +108,7 @@ ruleTester.run('display-name', rule, { ].join('\n'), options: [{ ignoreTranspilerName: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class Hello extends React.Component {', @@ -126,8 +121,7 @@ ruleTester.run('display-name', rule, { options: [{ ignoreTranspilerName: true }], - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ 'var Hello = createReactClass({', @@ -135,8 +129,7 @@ ruleTester.run('display-name', rule, { ' return
Hello {this.props.name}
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'class Hello extends React.Component {', @@ -163,8 +156,7 @@ ruleTester.run('display-name', rule, { ' return
Hello {this.props.name}
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'module.exports = createReactClass({', @@ -173,8 +165,7 @@ ruleTester.run('display-name', rule, { ' return
Hello {this.props.name}
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var Hello = createReactClass({', @@ -188,8 +179,7 @@ ruleTester.run('display-name', rule, { ].join('\n'), options: [{ ignoreTranspilerName: true - }], - parserOptions: parserOptions + }] }, { code: [ 'export default class {', @@ -421,7 +411,6 @@ ruleTester.run('display-name', rule, { options: [{ ignoreTranspilerName: true }], - parserOptions: parserOptions, errors: [{ message: 'Component definition is missing display name' }] @@ -441,7 +430,6 @@ ruleTester.run('display-name', rule, { createClass: 'createClass' } }, - parserOptions: parserOptions, errors: [{ message: 'Component definition is missing display name' }] @@ -456,7 +444,6 @@ ruleTester.run('display-name', rule, { options: [{ ignoreTranspilerName: true }], - parserOptions: parserOptions, errors: [{ message: 'Component definition is missing display name' }] @@ -471,7 +458,6 @@ ruleTester.run('display-name', rule, { options: [{ ignoreTranspilerName: true }], - parserOptions: parserOptions, errors: [{ message: 'Component definition is missing display name' }] @@ -489,7 +475,6 @@ ruleTester.run('display-name', rule, { options: [{ ignoreTranspilerName: true }], - parserOptions: parserOptions, errors: [{ message: 'Component definition is missing display name' }] diff --git a/tests/lib/rules/forbid-component-props.js b/tests/lib/rules/forbid-component-props.js index a9dc65d58a..ba4d2630ba 100644 --- a/tests/lib/rules/forbid-component-props.js +++ b/tests/lib/rules/forbid-component-props.js @@ -11,7 +11,8 @@ var rule = require('../../../lib/rules/forbid-component-props'); var RuleTester = require('eslint').RuleTester; var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -27,7 +28,7 @@ require('babel-eslint'); var CLASSNAME_ERROR_MESSAGE = 'Prop `className` is forbidden on Components'; var STYLE_ERROR_MESSAGE = 'Prop `style` is forbidden on Components'; -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('forbid-component-props', rule, { valid: [{ @@ -37,8 +38,7 @@ ruleTester.run('forbid-component-props', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -47,8 +47,7 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - options: [{forbid: ['style']}], - parserOptions: parserOptions + options: [{forbid: ['style']}] }, { code: [ 'var First = createReactClass({', @@ -57,8 +56,7 @@ ruleTester.run('forbid-component-props', rule, { ' return ;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -68,8 +66,7 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - options: [{forbid: ['style']}], - parserOptions: parserOptions + options: [{forbid: ['style']}] }, { code: [ 'var First = createReactClass({', @@ -79,8 +76,7 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - options: [{forbid: ['style', 'foo']}], - parserOptions: parserOptions + options: [{forbid: ['style', 'foo']}] }, { code: [ 'var First = createReactClass({', @@ -89,8 +85,7 @@ ruleTester.run('forbid-component-props', rule, { ' return ;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'class First extends createReactClass {', @@ -99,15 +94,13 @@ ruleTester.run('forbid-component-props', rule, { ' }', '}' ].join('\n'), - options: [{forbid: ['style']}], - parserOptions: parserOptions + options: [{forbid: ['style']}] }, { code: [ 'const First = (props) => (', ' ', ');' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }], invalid: [{ @@ -119,7 +112,6 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{ message: CLASSNAME_ERROR_MESSAGE, line: 4, @@ -135,7 +127,6 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{ message: STYLE_ERROR_MESSAGE, line: 4, @@ -151,7 +142,6 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, options: [{forbid: ['className', 'style']}], errors: [{ message: CLASSNAME_ERROR_MESSAGE, @@ -168,7 +158,6 @@ ruleTester.run('forbid-component-props', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, options: [{forbid: ['className', 'style']}], errors: [{ message: STYLE_ERROR_MESSAGE, diff --git a/tests/lib/rules/forbid-elements.js b/tests/lib/rules/forbid-elements.js index 0ab7fcdc1f..080a441885 100644 --- a/tests/lib/rules/forbid-elements.js +++ b/tests/lib/rules/forbid-elements.js @@ -11,7 +11,8 @@ var rule = require('../../../lib/rules/forbid-elements'); var RuleTester = require('eslint').RuleTester; var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -24,73 +25,60 @@ require('babel-eslint'); // Tests // ----------------------------------------------------------------------------- -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('forbid-elements', rule, { valid: [ { code: '', options: [{forbid: [{element: 'button'}, {element: 'input'}]}], - parserOptions: parserOptions, errors: [ {message: '', options: [{forbid: [{element: 'button'}, 'input']}], - parserOptions: parserOptions, errors: [ {message: '', options: [{forbid: ['input', {element: 'button'}]}], - parserOptions: parserOptions, errors: [ {message: ';', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { // Must allow us to re-order the groups code: [ @@ -91,8 +90,7 @@ ruleTester.run('sort-comp', rule, { 'render', 'everything-else' ] - }], - parserOptions: parserOptions + }] }, { // Must allow us to create a RegExp-based group code: [ @@ -111,8 +109,7 @@ ruleTester.run('sort-comp', rule, { 'render', '/on.*/' ] - }], - parserOptions: parserOptions + }] }, { // Must allow us to create a named group code: [ @@ -136,8 +133,7 @@ ruleTester.run('sort-comp', rule, { '/on.*/' ] } - }], - parserOptions: parserOptions + }] }, { // Must allow a method to be in different places if it's matches multiple patterns code: [ @@ -154,8 +150,7 @@ ruleTester.run('sort-comp', rule, { 'render', '/.*Click/' ] - }], - parserOptions: parserOptions + }] }, { // Must allow us to use 'constructor' as a method name code: [ @@ -174,8 +169,7 @@ ruleTester.run('sort-comp', rule, { 'everything-else', 'render' ] - }], - parserOptions: parserOptions + }] }, { // Must ignore stateless components code: [ @@ -215,7 +209,6 @@ ruleTester.run('sort-comp', rule, { '}' ].join('\n'), parser: 'babel-eslint', - parserOptions: parserOptions, options: [{ order: [ 'type-annotations', @@ -238,7 +231,6 @@ ruleTester.run('sort-comp', rule, { '}' ].join('\n'), parser: 'babel-eslint', - parserOptions: parserOptions, options: [{ order: [ 'type-annotations', @@ -260,7 +252,6 @@ ruleTester.run('sort-comp', rule, { ' displayName : \'Hello\',', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{message: 'render should be placed after displayName'}] }, { // Must run rule when render uses createElement instead of JSX @@ -272,7 +263,6 @@ ruleTester.run('sort-comp', rule, { ' displayName : \'Hello\',', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{message: 'render should be placed after displayName'}] }, { // Must force a custom method to be placed before render @@ -284,7 +274,6 @@ ruleTester.run('sort-comp', rule, { ' onClick: function() {},', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{message: 'render should be placed after onClick'}] }, { // Must force a custom method to be placed after render if no 'everything-else' group is specified @@ -303,7 +292,6 @@ ruleTester.run('sort-comp', rule, { 'render' ] }], - parserOptions: parserOptions, errors: [{message: 'onClick should be placed after render'}] }, { // Must validate static properties @@ -316,7 +304,6 @@ ruleTester.run('sort-comp', rule, { '}' ].join('\n'), parser: 'babel-eslint', - parserOptions: parserOptions, errors: [{message: 'render should be placed after displayName'}] }, { // Type Annotations should not be at the top by default @@ -331,7 +318,6 @@ ruleTester.run('sort-comp', rule, { '}' ].join('\n'), parser: 'babel-eslint', - parserOptions: parserOptions, errors: [{message: 'props should be placed after state'}] }, { // Type Annotations should be first diff --git a/tests/lib/rules/sort-prop-types.js b/tests/lib/rules/sort-prop-types.js index bdaf780a53..cd8996bbd6 100644 --- a/tests/lib/rules/sort-prop-types.js +++ b/tests/lib/rules/sort-prop-types.js @@ -11,7 +11,8 @@ var rule = require('../../../lib/rules/sort-prop-types'); var RuleTester = require('eslint').RuleTester; var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -26,7 +27,7 @@ require('babel-eslint'); var ERROR_MESSAGE = 'Prop types declarations should be sorted alphabetically'; -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('sort-prop-types', rule, { valid: [{ @@ -36,8 +37,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -46,8 +46,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -61,8 +60,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -79,8 +77,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ ignoreCase: true - }], - parserOptions: parserOptions + }] }, { code: [ 'var First = createReactClass({', @@ -101,8 +98,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'class First extends React.Component {', @@ -115,8 +111,7 @@ ruleTester.run('sort-prop-types', rule, { ' z: PropTypes.string', '};', 'First.propTypes.justforcheck = PropTypes.string;' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'class First extends React.Component {', @@ -133,8 +128,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ ignoreCase: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class Component extends React.Component {', @@ -148,8 +142,7 @@ ruleTester.run('sort-prop-types', rule, { ' }', '}' ].join('\n'), - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ 'class Hello extends React.Component {', @@ -189,8 +182,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -203,8 +195,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', ' }', '});' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'var First = createReactClass({', @@ -221,8 +212,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ callbacksLast: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class Component extends React.Component {', @@ -240,8 +230,7 @@ ruleTester.run('sort-prop-types', rule, { options: [{ callbacksLast: true }], - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ 'class First extends React.Component {', @@ -258,8 +247,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ callbacksLast: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class First extends React.Component {', @@ -274,8 +262,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ requiredFirst: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class First extends React.Component {', @@ -289,8 +276,7 @@ ruleTester.run('sort-prop-types', rule, { ].join('\n'), options: [{ requiredFirst: true - }], - parserOptions: parserOptions + }] }, { code: [ 'class First extends React.Component {', @@ -310,8 +296,7 @@ ruleTester.run('sort-prop-types', rule, { options: [{ requiredFirst: true, callbacksLast: true - }], - parserOptions: parserOptions + }] }, { code: [ 'export default class ClassWithSpreadInPropTypes extends BaseClass {', @@ -330,8 +315,7 @@ ruleTester.run('sort-prop-types', rule, { ' return
;', '};', 'TextFieldLabel.propTypes = propTypes;' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }], invalid: [{ @@ -346,7 +330,6 @@ ruleTester.run('sort-prop-types', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 4, @@ -365,7 +348,6 @@ ruleTester.run('sort-prop-types', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 4, @@ -387,7 +369,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ ignoreCase: true }], - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 4, @@ -408,7 +389,6 @@ ruleTester.run('sort-prop-types', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: 2 }, { code: [ @@ -431,7 +411,6 @@ ruleTester.run('sort-prop-types', rule, { ' }', '});' ].join('\n'), - parserOptions: parserOptions, errors: 2 }, { code: [ @@ -454,7 +433,6 @@ ruleTester.run('sort-prop-types', rule, { ' ZZ: PropTypes.string', '};' ].join('\n'), - parserOptions: parserOptions, errors: 2 }, { code: [ @@ -470,7 +448,6 @@ ruleTester.run('sort-prop-types', rule, { '}' ].join('\n'), parser: 'babel-eslint', - parserOptions: parserOptions, errors: 2 }, { code: [ @@ -489,7 +466,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ callbacksLast: true }], - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 6, @@ -514,7 +490,6 @@ ruleTester.run('sort-prop-types', rule, { callbacksLast: true }], parser: 'babel-eslint', - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 6, @@ -538,7 +513,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ callbacksLast: true }], - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 10, @@ -562,7 +536,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ callbacksLast: true }], - parserOptions: parserOptions, errors: [{ message: 'Callback prop types must be listed after all other prop types', line: 5, @@ -585,7 +558,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ requiredFirst: true }], - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 4, @@ -608,7 +580,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ requiredFirst: true }], - parserOptions: parserOptions, errors: [{ message: 'Required prop types must be listed before all other prop types', line: 4, @@ -644,7 +615,6 @@ ruleTester.run('sort-prop-types', rule, { '};', 'TextFieldLabel.propTypes = propTypes;' ].join('\n'), - parserOptions: parserOptions, errors: [{ message: ERROR_MESSAGE, line: 3, diff --git a/tests/lib/rules/style-prop-object.js b/tests/lib/rules/style-prop-object.js index 7c7346c76a..880cd99a27 100644 --- a/tests/lib/rules/style-prop-object.js +++ b/tests/lib/rules/style-prop-object.js @@ -12,7 +12,8 @@ var rule = require('../../../lib/rules/style-prop-object'); var RuleTester = require('eslint').RuleTester; var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -23,16 +24,14 @@ var parserOptions = { // Tests // ------------------------------------------------------------------------------ -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('style-prop-object', rule, { valid: [ { - code: '
', - parserOptions: parserOptions + code: '
' }, { - code: '', - parserOptions: parserOptions + code: '' }, { code: [ @@ -40,8 +39,7 @@ ruleTester.run('style-prop-object', rule, { ' const styles = { color: "red" };', ' return
;', '}' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -49,8 +47,7 @@ ruleTester.run('style-prop-object', rule, { ' const styles = { color: "red" };', ' return ;', '}' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -58,16 +55,14 @@ ruleTester.run('style-prop-object', rule, { 'function redDiv() {', ' return
;', '}' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'function redDiv(props) {', ' return
;', '}' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -75,8 +70,7 @@ ruleTester.run('style-prop-object', rule, { 'function redDiv() {', ' return
;', '}' - ].join('\n'), - parserOptions: Object.assign({sourceType: 'module'}, parserOptions) + ].join('\n') }, { code: [ @@ -86,15 +80,21 @@ ruleTester.run('style-prop-object', rule, { ' return
;', '}' ].join('\n'), - parserOptions: Object.assign({sourceType: 'module'}, parserOptions) + parserOptions: { + ecmaVersion: 8, + sourceType: 'module', + ecmaFeatures: { + experimentalObjectRestSpread: true, + jsx: true + } + } }, { code: [ 'const otherProps = { style: { color: "red" } };', 'const { a, b, ...props } = otherProps;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -104,64 +104,55 @@ ruleTester.run('style-prop-object', rule, { parserOptions: Object.assign({sourceType: 'module'}, parserOptions) }, { - code: '
', - parserOptions: parserOptions + code: '
' }, { code: [ 'React.createElement(MyCustomElem, {', ' [style]: true', '}, \'My custom Elem\')' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'let style;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'let style = null;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'let style = undefined;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { - code: '
', - parserOptions: parserOptions + code: '
' }, { code: [ 'const props = { style: undefined };', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'const otherProps = { style: undefined };', 'const { a, b, ...props } = otherProps;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'React.createElement("div", {', ' style: undefined', '})' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -169,35 +160,30 @@ ruleTester.run('style-prop-object', rule, { 'React.createElement("div", {', ' style', '})' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { - code: '
', - parserOptions: parserOptions + code: '
' }, { code: [ 'const props = { style: null };', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'const otherProps = { style: null };', 'const { a, b, ...props } = otherProps;', '
' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ 'React.createElement("div", {', ' style: null', '})' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') }, { code: [ @@ -206,8 +192,7 @@ ruleTester.run('style-prop-object', rule, { ' ...props', ' });', '};' - ].join('\n'), - parserOptions: parserOptions + ].join('\n') } ], invalid: [ @@ -218,8 +203,7 @@ ruleTester.run('style-prop-object', rule, { line: 1, column: 6, type: 'JSXAttribute' - }], - parserOptions: parserOptions + }] }, { code: '', @@ -228,8 +212,7 @@ ruleTester.run('style-prop-object', rule, { line: 1, column: 8, type: 'JSXAttribute' - }], - parserOptions: parserOptions + }] }, { code: '
', @@ -238,8 +221,7 @@ ruleTester.run('style-prop-object', rule, { line: 1, column: 6, type: 'JSXAttribute' - }], - parserOptions: parserOptions + }] }, { code: [ @@ -253,8 +235,7 @@ ruleTester.run('style-prop-object', rule, { line: 3, column: 22, type: 'Identifier' - }], - parserOptions: parserOptions + }] }, { code: [ @@ -268,8 +249,7 @@ ruleTester.run('style-prop-object', rule, { line: 3, column: 24, type: 'Identifier' - }], - parserOptions: parserOptions + }] }, { code: [ @@ -283,8 +263,7 @@ ruleTester.run('style-prop-object', rule, { line: 3, column: 22, type: 'Identifier' - }], - parserOptions: parserOptions + }] } ] }); diff --git a/tests/lib/rules/void-dom-elements-no-children.js b/tests/lib/rules/void-dom-elements-no-children.js index 112cbf21a9..6704f41ede 100644 --- a/tests/lib/rules/void-dom-elements-no-children.js +++ b/tests/lib/rules/void-dom-elements-no-children.js @@ -13,7 +13,8 @@ var rule = require('../../../lib/rules/void-dom-elements-no-children'); var RuleTester = require('eslint').RuleTester; var parserOptions = { - ecmaVersion: 6, + ecmaVersion: 8, + sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true @@ -28,91 +29,74 @@ function errorMessage(elementName) { // Tests // ----------------------------------------------------------------------------- -var ruleTester = new RuleTester(); +var ruleTester = new RuleTester({parserOptions}); ruleTester.run('void-dom-elements-no-children', rule, { valid: [ { - code: '
Foo
;', - parserOptions: parserOptions + code: '
Foo
;' }, { - code: '
;', - parserOptions: parserOptions + code: '
;' }, { - code: '
;', - parserOptions: parserOptions + code: '
;' }, { - code: 'React.createElement("div", {}, "Foo");', - parserOptions: parserOptions + code: 'React.createElement("div", {}, "Foo");' }, { - code: 'React.createElement("div", { children: "Foo" });', - parserOptions: parserOptions + code: 'React.createElement("div", { children: "Foo" });' }, { - code: 'React.createElement("div", { dangerouslySetInnerHTML: { __html: "Foo" } });', - parserOptions: parserOptions + code: 'React.createElement("div", { dangerouslySetInnerHTML: { __html: "Foo" } });' }, { - code: 'document.createElement("img")', - parserOptions: parserOptions + code: 'document.createElement("img")' }, { - code: 'React.createElement("img");', - parserOptions: parserOptions + code: 'React.createElement("img");' }, { code: [ 'import React from "react";', 'const { createElement } = React;', 'createElement("div")' ].join('\n'), - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ 'import React from "react";', 'const { createElement } = React;', 'createElement("img")' ].join('\n'), - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' } ], invalid: [ { code: '
Foo
;', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: '
;', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: ';', - errors: [{message: errorMessage('img')}], - parserOptions: parserOptions + errors: [{message: errorMessage('img')}] }, { code: '
;', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: 'React.createElement("br", {}, "Foo");', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: 'React.createElement("br", { children: "Foo" });', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: 'React.createElement("br", { dangerouslySetInnerHTML: { __html: "Foo" } });', - errors: [{message: errorMessage('br')}], - parserOptions: parserOptions + errors: [{message: errorMessage('br')}] }, { code: [ @@ -121,8 +105,7 @@ ruleTester.run('void-dom-elements-no-children', rule, { 'createElement("img", {}, "Foo");' ].join('\n'), errors: [{message: errorMessage('img')}], - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ @@ -131,8 +114,7 @@ ruleTester.run('void-dom-elements-no-children', rule, { 'createElement("img", { children: "Foo" });' ].join('\n'), errors: [{message: errorMessage('img')}], - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' }, { code: [ @@ -141,8 +123,7 @@ ruleTester.run('void-dom-elements-no-children', rule, { 'createElement("img", { dangerouslySetInnerHTML: { __html: "Foo" } });' ].join('\n'), errors: [{message: errorMessage('img')}], - parser: 'babel-eslint', - parserOptions: parserOptions + parser: 'babel-eslint' } ] });