Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

8 changes: 0 additions & 8 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.13
18
67 changes: 50 additions & 17 deletions __tests__/__snapshots__/check-fixtures.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ exports[`linting javascript.js fixture matches snapshot 1`] = `
"nodeType": "Identifier",
"ruleId": "no-unused-vars",
"severity": 2,
"suggestions": [
{
"data": {
"varName": "unusedEs6Import",
},
"desc": "Remove unused variable 'unusedEs6Import'.",
"fix": {
"range": [
0,
57,
],
"text": "",
},
"messageId": "removeVar",
},
],
},
{
"column": 1,
Expand Down Expand Up @@ -110,6 +126,22 @@ import { unusedEs6Import } from './stub/unusedEs6Import';
"nodeType": "Identifier",
"ruleId": "no-unused-vars",
"severity": 2,
"suggestions": [
{
"data": {
"varName": "y",
},
"desc": "Remove unused variable 'y'.",
"fix": {
"range": [
365,
366,
],
"text": "",
},
"messageId": "removeVar",
},
],
},
{
"column": 9,
Expand Down Expand Up @@ -203,8 +235,8 @@ import { unusedEs6Import } from './stub/unusedEs6Import';
"text": "Boolean('heyyy')",
},
"line": 47,
"message": "use \`Boolean('heyyy')\` instead.",
"messageId": "useRecommendation",
"message": "Unexpected implicit coercion encountered. Use \`Boolean('heyyy')\` instead.",
"messageId": "implicitCoercion",
"nodeType": "UnaryExpression",
"ruleId": "no-implicit-coercion",
"severity": 2,
Expand Down Expand Up @@ -280,17 +312,6 @@ exports[`linting typescript.ts fixture matches snapshot 1`] = `
"ruleId": "import/order",
"severity": 2,
},
{
"column": 10,
"endColumn": 25,
"endLine": 1,
"line": 1,
"message": "'unusedEs6Import' is defined but never used.",
"messageId": "unusedVar",
"nodeType": null,
"ruleId": "@typescript-eslint/no-unused-vars",
"severity": 2,
},
{
"column": 10,
"endColumn": 25,
Expand All @@ -309,6 +330,17 @@ exports[`linting typescript.ts fixture matches snapshot 1`] = `
"ruleId": "unused-imports/no-unused-imports",
"severity": 1,
},
{
"column": 10,
"endColumn": 25,
"endLine": 1,
"line": 1,
"message": "'unusedEs6Import' is defined but never used.",
"messageId": "unusedVar",
"nodeType": null,
"ruleId": "@typescript-eslint/no-unused-vars",
"severity": 2,
},
{
"column": 1,
"endColumn": 38,
Expand Down Expand Up @@ -351,10 +383,10 @@ import { unusedEs6Import } from './stub/unusedEs6Import';
"text": "string",
},
"line": 4,
"message": "Don't use \`String\` as a type. Use string instead",
"messageId": "bannedTypeMessage",
"message": "Prefer using the primitive \`string\` as a type name, rather than the upper-cased \`String\`.",
"messageId": "bannedClassType",
"nodeType": "Identifier",
"ruleId": "@typescript-eslint/ban-types",
"ruleId": "@typescript-eslint/no-wrapper-object-types",
"severity": 2,
},
{
Expand Down Expand Up @@ -386,7 +418,7 @@ import { unusedEs6Import } from './stub/unusedEs6Import';
"endColumn": 24,
"endLine": 16,
"line": 16,
"message": "Unsafe return of an \`any\` typed value.",
"message": "Unsafe return of a value of type \`any\`.",
"messageId": "unsafeReturn",
"nodeType": "Identifier",
"ruleId": "@typescript-eslint/no-unsafe-return",
Expand Down Expand Up @@ -589,6 +621,7 @@ import { unusedEs6Import } from './stub/unusedEs6Import';
"endLine": 67,
"line": 67,
"message": "@Controller should not have route prefixes.",
"messageId": "controllerPrefix",
"nodeType": "Decorator",
"ruleId": "@automattic/wpvip/nestjs-route-prefix",
"severity": 2,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/check-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function getLintMessages( fixture ) {
const rootPaths = [ __dirname, '..' ];
const eslint = new ESLint( {
ignore: false,
overrideConfigFile: path.resolve( ...rootPaths, '.eslintrc.js' ),
useEslintrc: false,
overrideConfigFile: path.resolve( ...rootPaths, 'eslint.config.js' ),
baseConfig: null,
} );

const [ { messages } ] = await eslint.lintFiles(
Expand Down
49 changes: 18 additions & 31 deletions __tests__/rules/nestjs-route-prefix.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/**
* External dependencies
*/
import { Linter, RuleTester } from 'eslint';
import * as tsEsLintParser from '@typescript-eslint/parser';
import { type Linter, RuleTester } from 'eslint';

/**
* Internal dependencies
*/
import rule from '../../rules/nestjs-route-prefix';

const ruleTester = new RuleTester( { parser: require.resolve( '@typescript-eslint/parser' ) } );
const parserOptions: Linter.ParserOptions = { ecmaVersion: 8 };
const languageOptions: Linter.LanguageOptions = {
ecmaVersion: 'latest',
parser: tsEsLintParser,
parserOptions: {
ecmaVersion: 'latest',
},
};

const ruleTester = new RuleTester( {
languageOptions,
} );

describe( 'nestjs-routes', () => {
ruleTester.run( 'nestjs-routes', rule, {
Expand All @@ -19,28 +23,24 @@ describe( 'nestjs-routes', () => {
@Get('/hello/w*d')
export class CustomController {}
`,
parserOptions,
},
{
code: `
@Get('/:id')
export class CustomController {}
`,
parserOptions,
},
{
code: `
@Controller()
export class CustomController {}
`,
parserOptions,
},
{
code: `
@Controller({ host: 'example.org' })
export class CustomController {}
`,
parserOptions,
},
],
invalid: [
Expand All @@ -49,48 +49,35 @@ describe( 'nestjs-routes', () => {
@Controller('/v1')
export class CustomController {}
`,
errors: [ { message: '@Controller should not have route prefixes.' } ],
parserOptions,
errors: [ { messageId: 'controllerPrefix' } ],
},
{
code: `
@Get('hello/world/')
export class CustomController {}
`,
errors: [
{ message: "@Get should have a route starting with '/' and not ending with '/'." },
],
parserOptions,
errors: [ { messageId: 'decoratorSlash', data: { decoratorName: 'Get' } } ],
},
{
code: `
@Get('')
export class CustomController {}
`,
errors: [
{ message: "@Get should have a route starting with '/' and not ending with '/'." },
],
parserOptions,
errors: [ { messageId: 'decoratorSlash', data: { decoratorName: 'Get' } } ],
},
{
code: `
@Post('/hello/world/')
export class CustomController {}
`,
errors: [
{ message: "@Post should have a route starting with '/' and not ending with '/'." },
],
parserOptions,
errors: [ { messageId: 'decoratorSlash', data: { decoratorName: 'Post' } } ],
},
{
code: `
@Get(':id')
export class CustomController {}
`,
errors: [
{ message: "@Get should have a route starting with '/' and not ending with '/'." },
],
parserOptions,
errors: [ { messageId: 'decoratorSlash', data: { decoratorName: 'Get' } } ],
},
],
} );
Expand Down
17 changes: 6 additions & 11 deletions __tests__/rules/no-async-foreach.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
/**
* External dependencies
*/
import { Linter, RuleTester } from 'eslint';

/**
* Internal dependencies
*/
/** @type {import('eslint').Rule.RuleModule} */
import rule from '../../rules/no-async-foreach';

const ruleTester = new RuleTester();
const parserOptions: Linter.ParserOptions = { ecmaVersion: 8 };
const languageOptions: Linter.LanguageOptions = { ecmaVersion: 8 };
const errors = [ { message: 'Avoid passing an async function to Array.prototype.forEach' } ];

describe( 'no-async-foreach', () => {
ruleTester.run( 'no-async-foreach', rule, {
valid: [
{
code: '[].forEach(() => {})',
parserOptions,
languageOptions,
},
{
code: '[].forEach(function() {})',
parserOptions,
languageOptions,
},
],
invalid: [
{
code: '[].forEach(async () => {})',
errors,
parserOptions,
languageOptions,
},
{
code: '[].forEach(async function() {})',
errors,
parserOptions,
languageOptions,
},
],
} );
Expand Down
25 changes: 14 additions & 11 deletions configs/cli.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module.exports = {
/**
* Please include a short description of the rule. For rules that downgrade or
* disable errors, include a brief justification or reasoning.
*/
rules: {
// Allow child_process and non-literal `exec` arguments.
'security/detect-child-process': 'off',
/** @type import('eslint').Linter.Config[] */
module.exports = [
{
/**
* Please include a short description of the rule. For rules that downgrade or
* disable errors, include a brief justification or reasoning.
*/
rules: {
// Allow child_process and non-literal `exec` arguments.
'security/detect-child-process': 'off',

// Process.exit is used in CLI context to stop execution.
'no-process-exit': 'off',
// Process.exit is used in CLI context to stop execution.
'no-process-exit': 'off',
},
},
};
];
Loading