How to use the eslint.RuleTester function in eslint

To help you get started, we’ve selected a few eslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / eslint-plugin-vue / tests / lib / rules / valid-v-cloak.js View on Github external
* See LICENSE file in root directory for full license.
 */
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/valid-v-cloak')

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const tester = new RuleTester({
  parser: require.resolve('vue-eslint-parser'),
  parserOptions: { ecmaVersion: 2015 }
})

tester.run('valid-v-cloak', rule, {
  valid: [
    {
      filename: 'test.vue',
      code: ''
    },
    {
      filename: 'test.vue',
      code: '<template><div></div></template>'
    }
  ],
  invalid: [
github vuejs / eslint-plugin-vue / tests / lib / rules / no-boolean-default.js View on Github external
*/
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

var rule = require('../../../lib/rules/no-boolean-default')

var RuleTester = require('eslint').RuleTester

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester({
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module'
  }
})
ruleTester.run('no-boolean-default', rule, {

  valid: [
    {
      filename: 'test.vue',
      code: `
        export default {
          props: {
            enabled: Boolean
          }
        }
github ecomfe / fecs / test / lib / js / rules / max-destructure-depth.spec.js View on Github external
* @author chris
 */
'use strict';

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var rule = require('../../../../lib/js/rules/max-destructure-depth');
var RuleTester = require('eslint').RuleTester;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

var ruleTester = new RuleTester({parser: 'babel-eslint'});

ruleTester.run('max-destructure-depth', rule, {
    valid: [
        '[a] = b;',
        'let [a] = b;',
        'let [a, b] = c;',
        'let {a: [b]} = c;',
        'let [a, b, c] = d;',
        'let [a, [b], [c]] = d;',
        'let [a, [b], {c}] = d;',
        '({a} = b);',
        'let {a} = b;',
        'let {a, b} = c;',
        'let {a, b, c} = d;',
        'let {a: {b}} = c;',
        'let {a: {b}, c: {d}} = e;',
github ilyavolodin / eslint-plugin-backbone / tests / lib / rules / no-model-attributes.js View on Github external
* @author Ilya Volodin
 */
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var RuleTester = require("eslint").RuleTester;
var rule = require("../../../lib/rules/no-model-attributes");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

var eslintTester = new RuleTester();
eslintTester.run("no-model-attributes", rule, {

    valid: [
        "Backbone.Model.extend({});",
        "Backbone.Model.extend({ initialize: function() { } });",
        "Backbone.Model.extend({ initialize: function() { alert(this.get('test')); } });",
        "Backbone.Model.extend({ initialize: function() { this.set('test', true); } });"
    ],

    invalid: [
        {
            code: "Backbone.Model.extend({ initialize: function() { alert(this.attributes); } });",
            errors: [ { message: "Do not access attributes directly. Use set() and get() instead" } ]
        },
        {
            code: "Backbone.Model.extend({ initialize: function() { _.first(this.attributes); } });",
github ember-cli / eslint-plugin-ember / tests / lib / rules / no-on-calls-in-components.js View on Github external
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-on-calls-in-components');
const RuleTester = require('eslint').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester({
  parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});

const message = "Don't use .on() for component lifecycle events.";

eslintTester.run('no-on-calls-in-components', rule, {
  valid: [
    'export default Component.extend();',
    'export default Component.extend({actions: {}});',
    'export default Component.extend({abc: service()});',
    'export default Component.extend({abc: inject.service()});',
    'export default Component.extend({abc: false});',
    'export default Component.extend({classNames: ["abc", "def"]});',
    'export default Component.extend({abc: computed(function () {})});',
    'export default Component.extend({abc: observer("abc", function () {})});',
    'export default Component.extend({abc: observer("abc", function () {test.on("xyz", def)})});',
github EmmanuelDemey / eslint-plugin-angular / test / module-getter.js View on Github external
'use strict';

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

var rule = require('../rules/module-getter');
var RuleTester = require('eslint').RuleTester;
var commonFalsePositives = require('./utils/commonFalsePositives');

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var eslintTester = new RuleTester();
eslintTester.run('module-getter', rule, {
    valid: [
        'require.config({});',
        'angular.module("module").config(function(jwtOptionsProvider){' +
            'jwtOptionsProvider.config({' +
                'whiteListedDomains: []' +
            '});' +
        '})',
        'angular.module("module").config(function(ngTableHelperProvider){' +
            'ngTableHelperProvider.config({count: 10}, {});' +
        '})',
        'angular.module("module").controller("ctrl", function(ReportService) { ReportService.run();});',
        'angular.module("module").controller("TestCtrl", function() {});',
        'angular.module("module").factory("TestService", function() {});',
        'angular.module("module").service("TestService", function() {});',
        'angular.module("module").directive("testDirective", function() {});',
github vuejs / eslint-plugin-vue / tests / lib / rules / no-invalid-v-bind.js View on Github external
* See LICENSE file in root directory for full license.
 */
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/no-invalid-v-bind')

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const tester = new RuleTester({
  parser: 'vue-eslint-parser',
  parserOptions: { ecmaVersion: 2015 }
})

tester.run('no-invalid-v-bind', rule, {
  valid: [
    {
      filename: 'test.vue',
      code: ''
    },
    {
      filename: 'test.vue',
      code: '<template><div></div></template>'
    },
    {
      filename: 'test.vue',
github alecxe / eslint-plugin-protractor / test / rules / no-execute-script.js View on Github external
'use strict'

var rule = require('../../lib/rules/no-execute-script')
var RuleTester = require('eslint').RuleTester
var eslintTester = new RuleTester()

eslintTester.run('no-execute-script', rule, {
  valid: [
    'var test = "bar"',
    'test();',
    'browser.get("test");',
    'browser.browser',
    'obj.executeScript("something");',
    '',

    {
      code: 'test.test();',
      settings: {
        'eslint-plugin-protractor': {
          paths: {
            specs: ['**/*.spec.js', '*.spec.js']
github ember-best-practices / eslint-plugin-ember-best-practices / tests / lib / rules / no-side-effect-cp.js View on Github external
const rule = require('../../../lib/rules/no-side-effect-cp');
const MESSAGE = rule.meta.message;
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module'
  }
});

ruleTester.run('no-side-efffect-cp', rule, {
  valid: [
    {
      code: `
        export default Ember.Component({
          foo: 'bar',
          baz: false,
          actions: {
            userInput() {
              this.set('baz', true);
github alecxe / eslint-plugin-protractor / test / rules / no-get-inner-outer-html.js View on Github external
'use strict'

var rule = require('../../lib/rules/no-get-inner-outer-html')
var RuleTester = require('eslint').RuleTester

var eslintTester = new RuleTester()

eslintTester.run('no-get-inner-outer-html', rule, {
  valid: [
    'expect(element(by.id("myid")).getText()).toEqual("test");',
    'getInnerHtml();',
    'var html = getOuterHtml();',
    'elm.getInnerHtml();',
    'elm.getOuterHtml();'
  ],

  invalid: [
    {
      code: 'expect(element(by.id("myid")).getInnerHtml()).toEqual("test");',
      errors: [
        {
          message: 'Unexpected "getInnerHtml()"'