How to use the eslint.RuleTester.setDefaultConfig 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 mysticatea / eslint-plugin-es / tests / tester.js View on Github external
const { Linter, RuleTester } = require("eslint")
const { builtin } = require("globals")
const semver = require("semver")

const eslintVersion = new Linter().version
const ecmaVersion =
    /*eslint-disable @mysticatea/prettier */
    semver.gte(eslintVersion, "6.2.0") ? 2020 :
    semver.gte(eslintVersion, "5.0.0") ? 2019 :
    2018
    /*eslint-enable @mysticatea/prettier */

//eslint-disable-next-line no-console
console.log("ECMAScript Version: %d", ecmaVersion)

RuleTester.setDefaultConfig({
    parserOptions: {
        ecmaVersion,
        sourceType: "script",
    },
    globals: builtin,
})
RuleTester.isSupported = targetEcmaVersion => targetEcmaVersion <= ecmaVersion

module.exports = RuleTester
github you-dont-need / You-Dont-Need-Momentjs / lib / __tests__ / index.js View on Github external
const rule = require('../').rules;
const RuleTester = require('eslint').RuleTester;

RuleTester.setDefaultConfig({
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
  },
});

var ruleTester = new RuleTester();

describe('ESLint plugin', () => {
  ruleTester.run('no-dynamic-import-moment', rule['no-dynamic-import-moment'], {
    valid: ["import('date-fns').then()"],
    invalid: [
      {
        code: "import('moment').then(()=>{})",
        errors: [
github sagiavinash / eslint-plugin-organize-imports / tests / lib / rules / organize-imports.js View on Github external
import path from 'path';
import { RuleTester } from 'eslint';
import rule from '../../../lib/rules/organize-imports';

RuleTester.setDefaultConfig({ parser: 'babel-eslint' });

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

const injectConfig = (testCases, testConfig) => ({
  ...testCases,
  valid: testCases.valid.map((testCase) => ({ ...testCase, ...testConfig })),
  invalid: testCases.invalid.map((testCase) => ({ ...testCase, ...testConfig })),
});

const testEslintConfig = {
  options: [
    {
      orderRules: [
        {
github lukastaegert / eslint-plugin-tree-shaking / tests / lib / rules / no-side-effects-in-initialization.js View on Github external
const rule = require('../../../lib/rules/no-side-effects-in-initialization')
const { Linter, RuleTester } = require('eslint')
const rollup = require('rollup')

const RULE_NAME = 'no-side-effects-in-initialization'

const PARSER_OPTIONS = {
  ecmaVersion: 2017,
  sourceType: 'module'
}

const PARSER_BABEL = require.resolve('babel-eslint')
const PARSER_TYPESCRIPT = require.resolve('@typescript-eslint/parser')

RuleTester.setDefaultConfig({
  parserOptions: PARSER_OPTIONS
})
const ruleTester = new RuleTester()

const linter = new Linter()
linter.defineRule(RULE_NAME, rule)

const createRollupOutput = code =>
  rollup
    .rollup({
      input: 'main',
      treeshake: { unknownGlobalSideEffects: false, propertyReadSideEffects: false },
      plugins: {
        resolveId (id) {
          return id
        },
github GlebkaF / eslint-plugin-strict-vue / tests / lib / rules / no-root-store-assets.js View on Github external
const R = require("ramda")
const { RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-root-store-assets")
const { prepareCases } = require("../../utils")

RuleTester.setDefaultConfig({
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: "module",
  },
})

const ruleTester = new RuleTester()

const invalidCases = [
  {
    title: "Root state and getters used by getters",
    code: `
    const getter5 = function(state, getters, { a }, { b }) {};

    const store = {
        state: {},
github GlebkaF / eslint-plugin-strict-vue / tests / lib / rules / require-jsdoc.js View on Github external
const { RuleTester } = require("eslint")
const rule = require("../../../lib/rules/require-jsdoc")
const { prepareCases } = require("../../utils")

RuleTester.setDefaultConfig({
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: "module",
  },
})

const ruleTester = new RuleTester()

const ERROR_MESSAGE = "Missing JSDoc comment."
const ACTION_PROP = "actions"

const OPTIONS = [
  {
    require: {
      VueProps: true,
      VuexActions: true,
github sagiavinash / eslint-plugin-organize-imports / tests / lib / rules / import-comments.js View on Github external
import path from 'path';
import { RuleTester } from 'eslint';
import rule from '../../../lib/rules/import-comments';

RuleTester.setDefaultConfig({ parser: 'babel-eslint' });

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

const injectConfig = (testCases, testConfig) => ({
  ...testCases,
  valid: testCases.valid.map((testCase) => ({ ...testCase, ...testConfig })),
  invalid: testCases.invalid.map((testCase) => ({ ...testCase, ...testConfig })),
});

const testEslintConfig = {
  options: [
    {
      commentRules: [
        {
github unlight / eslint-plugin-nestjs / src / use-validation-pipe / use-validation-pipe.spec.ts View on Github external
import { useValidationPipe, message } from './use-validation-pipe';
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester({
    parser: 'typescript-eslint-parser'
});
RuleTester.setDefaultConfig({
    parserOptions: {
        ecmaVersion: 2017,
        sourceType: 'module',
        ecmaFeatures: {},
    },
});

ruleTester.run('use-validation-pipe', useValidationPipe, {
    invalid: [
        { code: `@Controller('example') export class ExampleController { @Post() createOne(@Body() item: MyType) { } }`, errors: [{ message }] },
        { code: `class { @Post() async create(@Body() createCatDto: CreateCatDto) { } }`, errors: [{ message }] },
    ],
    valid: [
        { code: `class { @Post() @UsePipes(new ValidationPipe()) async create(@Body() createCatDto: CreateCatDto) { } }` },
        { code: `class { @Post() @UsePipes(new OtherPipe(), new ValidationPipe()) async create(@Body() createCatDto: CreateCatDto) { } }` },
        { code: `class { @Post() async create(@Body(new ValidationPipe()) createCatDto: CreateCatDto) { } }` },
github unlight / eslint-plugin-nestjs / src / deprecated-api-modules / deprecated-api-modules.spec.ts View on Github external
import { deprecatedApiModules, message } from './deprecated-api-modules';
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester({
    parser: 'typescript-eslint-parser'
});
RuleTester.setDefaultConfig({
    parserOptions: {
        ecmaVersion: 2017,
        sourceType: 'module',
        ecmaFeatures: {},
    },
});

ruleTester.run('deprecated-api-modules', deprecatedApiModules, {
    invalid: [
        { code: `@Module({ modules: [DatabaseModule] }) export class CatModule { }`, errors: [{ message, column: 11 }] },
    ],
    valid: [
        { code: `@Module({ imports: [DatabaseModule] }) export class CatModule { }`, errors: [{}] },
    ],
});
github unlight / eslint-plugin-nestjs / src / parse-int-pipe / parse-int-pipe.spec.ts View on Github external
import { parseIntPipe, message } from './parse-int-pipe';
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester({
    parser: 'typescript-eslint-parser'
});
RuleTester.setDefaultConfig({
    parserOptions: {
        ecmaVersion: 2017,
        sourceType: 'module',
        ecmaFeatures: {},
    },
});

ruleTester.run('parse-int-pipe', parseIntPipe, {
    invalid: [
        { code: `class { cat( @Param('any') id) { var n = parseInt(id) } }`, errors: [{ message: message.prefer }] },
        { code: `class { cat( @Param('any') id) { var n = Number.parseInt(id, 10) } }`, errors: [{ message: message.prefer }] },
        { code: `class { cat( @Param('any') id) { var n = Number(id) } }`, errors: [{ message: message.prefer }] },
        { code: `class { cat( @Param('any') id) { var n = +(id) } }`, errors: [{ message: message.prefer }] },
        { code: `class { cat( @Param('any', new ParseIntPipe()) id) { +(id) } }`, errors: [{ message: message.transformed.replace('{{name}}', 'id') }] },
    ],
    valid: [