Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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: [
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: [
{
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
},
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: {},
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,
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: [
{
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) { } }` },
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: [{}] },
],
});
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: [