Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new package rule-tester #6777

Merged
merged 13 commits into from
Apr 27, 2023
Merged
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ packages/types/src/generated/**/*.ts

# Playground types downloaded from the web
packages/website/src/vendor

# see the file header in eslint-base.test.js for more info
packages/rule-tester/tests/eslint-base
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ CHANGELOG.md

packages/website/.docusaurus
packages/website/build

# see the file header in eslint-base.test.js for more info
packages/rule-tester/tests/eslint-base
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@
"${workspaceFolder}/packages/scope-manager/dist/index.js",
],
},
{
"type": "node",
"request": "launch",
"name": "Run currently opened rule-tester test",
"cwd": "${workspaceFolder}/packages/rule-tester/",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"args": [
"--runInBand",
"--no-cache",
"--no-coverage",
"${fileBasename}"
],
"sourceMaps": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"${workspaceFolder}/packages/utils/src/index.ts",
"${workspaceFolder}/packages/utils/dist/index.js",
"${workspaceFolder}/packages/utils/src/ts-estree.ts",
"${workspaceFolder}/packages/utils/dist/ts-estree.js",
"${workspaceFolder}/packages/type-utils/src/ts-estree.ts",
"${workspaceFolder}/packages/type-utils/dist/ts-estree.js",
"${workspaceFolder}/packages/parser/src/index.ts",
"${workspaceFolder}/packages/parser/dist/index.js",
"${workspaceFolder}/packages/rule-tester/src/index.ts",
"${workspaceFolder}/packages/rule-tester/dist/index.js",
"${workspaceFolder}/packages/typescript-estree/src/index.ts",
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
"${workspaceFolder}/packages/types/src/index.ts",
"${workspaceFolder}/packages/types/dist/index.js",
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
"${workspaceFolder}/packages/scope-manager/dist/index.js",
"${workspaceFolder}/packages/scope-manager/dist/index.js",
],
},
{
"type": "node",
"request": "launch",
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-tslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/utils": "5.56.0",
"lodash": "^4.17.21"
"@typescript-eslint/utils": "5.56.0"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0",
Expand Down
19 changes: 18 additions & 1 deletion packages/eslint-plugin-tslint/src/rules/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { ESLintUtils } from '@typescript-eslint/utils';
import memoize from 'lodash/memoize';
import type { RuleSeverity } from 'tslint';
import { Configuration } from 'tslint';

import { CustomLinter } from '../custom-linter';

function memoize<T extends (...args: never[]) => unknown>(
func: T,
resolver: (...args: Parameters<T>) => string,
): T {
const cache = new Map<string, ReturnType<T>>();
const memoized = function (...args) {
const key = resolver(...(args as Parameters<T>));

if (cache.has(key)) {
return cache.get(key)!;
}
const result = func(...args);
cache.set(key, result as ReturnType<T>);
return result;
} as T;
return memoized;
}

bradzacher marked this conversation as resolved.
Show resolved Hide resolved
// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const version: string = require('../../package.json');
Expand Down
21 changes: 21 additions & 0 deletions packages/rule-tester/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 typescript-eslint and other contributors
bradzacher marked this conversation as resolved.
Show resolved Hide resolved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions packages/rule-tester/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `@typescript-eslint/rule-tester`

> Tooling to test ESLint rules

[![NPM Version](https://img.shields.io/npm/v/@typescript-eslint/rule-tester.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/rule-tester)
[![NPM Downloads](https://img.shields.io/npm/dm/@typescript-eslint/rule-tester.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/rule-tester)

👉 See **https://typescript-eslint.io/architecture/rule-tester** for documentation on this package.
7 changes: 7 additions & 0 deletions packages/rule-tester/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...require('../../jest.config.base.js'),
};
79 changes: 79 additions & 0 deletions packages/rule-tester/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "@typescript-eslint/rule-tester",
"version": "5.56.0",
"description": "Tooling to test ESLint rules",
"files": [
"dist",
"_ts4.2",
"README.md",
"LICENSE"
],
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/typescript-eslint/typescript-eslint.git",
"directory": "packages/rule-tester"
},
"bugs": {
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
},
"license": "MIT",
"keywords": [
"eslint",
"typescript",
"estree"
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"postbuild": "downlevel-dts dist _ts4.2/dist --to=4.2",
"clean": "tsc -b tsconfig.build.json --clean",
"postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage",
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"lint": "nx lint",
"pretest-eslint-base": "tsc -b tsconfig.build.json",
"test-eslint-base": "mocha --require source-map-support/register ./tests/eslint-base/eslint-base.test.js",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"//": "NOTE - AJV is out-of-date, but it's intentionally synced with ESLint - https://github.com/eslint/eslint/blob/ad9dd6a933fd098a0d99c6a9aa059850535c23ee/package.json#L70",
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"@typescript-eslint/typescript-estree": "5.56.0",
"@typescript-eslint/utils": "5.56.0",
"lodash.merge": "4.6.2",
"semver": "^7.3.7",
"ajv": "^6.10.0"
},
"peerDependencies": {
"@eslint/eslintrc": ">=2",
"eslint": ">=8"
},
"devDependencies": {
"@typescript-eslint/parser": "5.56.0",
"@types/lodash.merge": "4.6.7",
"chai": "^4.0.1",
"mocha": "^8.3.2",
"sinon": "^11.0.0",
"source-map-support": "^0.5.21"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/typescript-eslint"
},
"typesVersions": {
"<3.8": {
"*": [
"_ts3.4/*"
]
}
}
}
15 changes: 15 additions & 0 deletions packages/rule-tester/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "rule-tester",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"type": "library",
"implicitDependencies": [],
"targets": {
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/rule-tester/**/*.ts"]
}
}
}
}