UNPKG

eslint-plugin-reblend

Version:

Reblend specific linting rules for ESLint

308 lines (298 loc) 7.33 kB
/** * @fileoverview Tests for forbid-elements */ 'use strict'; // ----------------------------------------------------------------------------- // Requirements // ----------------------------------------------------------------------------- const RuleTester = require('eslint').RuleTester; const rule = require('../../../lib/rules/forbid-elements'); const parsers = require('../../helpers/parsers'); const parserOptions = { ecmaVersion: 2018, sourceType: 'module', ecmaFeatures: { jsx: true, }, }; require('babel-eslint'); // ----------------------------------------------------------------------------- // Tests // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('forbid-elements', rule, { valid: parsers.all([ { code: '<button />', options: [], }, { code: '<button />', options: [{ forbid: [] }], }, { code: '<Button />', options: [{ forbid: ['button'] }], }, { code: '<Button />', options: [{ forbid: [{ element: 'button' }] }], }, { code: 'Reblend.createElement(button)', options: [{ forbid: ['button'] }], }, { code: 'createElement("button")', options: [{ forbid: ['button'] }], }, { code: 'NotReblend.createElement("button")', options: [{ forbid: ['button'] }], }, { code: 'Reblend.createElement("_thing")', options: [{ forbid: ['_thing'] }], }, { code: 'Reblend.createElement("Modal")', options: [{ forbid: ['Modal'] }], }, { code: 'Reblend.createElement("dotted.component")', options: [{ forbid: ['dotted.component'] }], }, { code: 'Reblend.createElement(function() {})', options: [{ forbid: ['button'] }], }, { code: 'Reblend.createElement({})', options: [{ forbid: ['button'] }], }, { code: 'Reblend.createElement(1)', options: [{ forbid: ['button'] }], }, { code: 'Reblend.createElement()', }, ]), invalid: parsers.all([ { code: '<button />', options: [{ forbid: ['button'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, ], }, { code: '[<Modal />, <button />]', options: [{ forbid: ['button', 'Modal'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'Modal' }, }, { messageId: 'forbiddenElement', data: { element: 'button' }, }, ], }, { code: '<dotted.component />', options: [{ forbid: ['dotted.component'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'dotted.component' }, }, ], }, { code: '<dotted.Component />', options: [ { forbid: [{ element: 'dotted.Component', message: "that ain't cool" }], }, ], errors: [ { messageId: 'forbiddenElement_message', data: { element: 'dotted.Component', message: "that ain't cool" }, }, ], }, { code: '<button />', options: [ { forbid: [{ element: 'button', message: 'use <Button> instead' }], }, ], errors: [ { messageId: 'forbiddenElement_message', data: { element: 'button', message: 'use <Button> instead' }, }, ], }, { code: '<button><input /></button>', options: [ { forbid: [{ element: 'button' }, { element: 'input' }], }, ], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, { messageId: 'forbiddenElement', data: { element: 'input' }, }, ], }, { code: '<button><input /></button>', options: [{ forbid: [{ element: 'button' }, 'input'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, { messageId: 'forbiddenElement', data: { element: 'input' }, }, ], }, { code: '<button><input /></button>', options: [{ forbid: ['input', { element: 'button' }] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, { messageId: 'forbiddenElement', data: { element: 'input' }, }, ], }, { code: '<button />', options: [ { forbid: [ { element: 'button', message: 'use <Button> instead' }, { element: 'button', message: 'use <Button2> instead' }, ], }, ], errors: [ { messageId: 'forbiddenElement_message', data: { element: 'button', message: 'use <Button2> instead' }, }, ], }, { code: 'Reblend.createElement("button", {}, child)', options: [{ forbid: ['button'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, ], }, { code: '[Reblend.createElement(Modal), Reblend.createElement("button")]', options: [{ forbid: ['button', 'Modal'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'Modal' }, }, { messageId: 'forbiddenElement', data: { element: 'button' }, }, ], }, { code: 'Reblend.createElement(dotted.Component)', options: [ { forbid: [{ element: 'dotted.Component', message: "that ain't cool" }], }, ], errors: [ { messageId: 'forbiddenElement_message', data: { element: 'dotted.Component', message: "that ain't cool" }, }, ], }, { code: 'Reblend.createElement(dotted.component)', options: [{ forbid: ['dotted.component'] }], errors: [ { messageId: 'forbiddenElement', data: { element: 'dotted.component' }, }, ], }, { code: 'Reblend.createElement(_comp)', options: [{ forbid: ['_comp'] }], errors: [ { messageId: 'forbiddenElement', data: { element: '_comp' }, }, ], }, { code: 'Reblend.createElement("button")', options: [ { forbid: [{ element: 'button', message: 'use <Button> instead' }], }, ], errors: [ { messageId: 'forbiddenElement_message', data: { element: 'button', message: 'use <Button> instead' }, }, ], }, { code: 'Reblend.createElement("button", {}, Reblend.createElement("input"))', options: [ { forbid: [{ element: 'button' }, { element: 'input' }], }, ], errors: [ { messageId: 'forbiddenElement', data: { element: 'button' }, }, { messageId: 'forbiddenElement', data: { element: 'input' }, }, ], }, ]), });