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 package.json exports for public packages #6458

Merged
merged 10 commits into from Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 12 additions & 14 deletions .eslintignore
@@ -1,18 +1,16 @@
node_modules
dist
jest.config.js
fixtures
coverage
__snapshots__
.docusaurus
build

**/node_modules
**/dist
**/jest.config.js
**/fixtures
**/coverage
**/__snapshots__
**/.docusaurus
**/build
packages/eslint-plugin-tslint/tests
# Files copied as part of the build
packages/types/src/generated/**/*.ts
packages/website-eslint/typings/eslint.d.ts

# TODO - enable linting for JS files (need to also add them to the project.json)
packages/website/**/*.js
packages/website/**/*.d.ts
packages/website-eslint/**/*.js
packages/website-eslint/**/*.d.ts

# Files copied as part of the build
packages/types/src/generated/**/*.ts
119 changes: 70 additions & 49 deletions .eslintrc.js
Expand Up @@ -18,38 +18,11 @@ module.exports = {
'eslint:recommended',
'plugin:eslint-plugin/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
parserOptions: {
sourceType: 'module',
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
'./tests/integration/tsconfig.json',
/**
* We are currently in the process of transitioning to nx's out of the box structure and
* so need to manually specify converted packages' tsconfig.build.json and tsconfig.spec.json
* files here for now in addition to the tsconfig.json glob pattern.
*
* TODO(#4665): Clean this up once all packages have been transitioned.
*/
'./packages/scope-manager/tsconfig.build.json',
'./packages/scope-manager/tsconfig.spec.json',
],
allowAutomaticSingleRunInference: true,
tsconfigRootDir: __dirname,
warnOnUnsupportedTypeScriptVersion: false,
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: false,
cacheLifetime: {
// we pretty well never create/change tsconfig structure - so need to ever evict the cache
// in the rare case that we do - just need to manually restart their IDE.
glob: 'Infinity',
},
},
rules: {
// make sure we're not leveraging any deprecated APIs
'deprecation/deprecation': 'error',

//
// our plugin :D
//
Expand All @@ -69,8 +42,6 @@ module.exports = {
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: true },
],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] },
Expand All @@ -79,33 +50,13 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowAny: true,
allowNullish: true,
allowRegExp: true,
},
],
'@typescript-eslint/no-unused-vars': [
'warn',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],

//
// Internal repo rules
//

'@typescript-eslint/internal/no-poorly-typed-ts-props': 'error',
'@typescript-eslint/internal/no-typescript-default-import': 'error',
'@typescript-eslint/internal/prefer-ast-types-enum': 'error',

//
// eslint-base
//
Expand Down Expand Up @@ -202,6 +153,76 @@ module.exports = {
'one-var': ['error', 'never'],
},
overrides: [
// only turn on type-aware linting for TS files
{
files: ['*.ts', '*.tsx'],
extends: [
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
parserOptions: {
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
'./tests/integration/tsconfig.json',
/**
* We are currently in the process of transitioning to nx's out of the box structure and
* so need to manually specify converted packages' tsconfig.build.json and tsconfig.spec.json
* files here for now in addition to the tsconfig.json glob pattern.
*
* TODO(#4665): Clean this up once all packages have been transitioned.
*/
'./packages/scope-manager/tsconfig.build.json',
'./packages/scope-manager/tsconfig.spec.json',
],
allowAutomaticSingleRunInference: true,
tsconfigRootDir: __dirname,
warnOnUnsupportedTypeScriptVersion: false,
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: false,
cacheLifetime: {
// we pretty well never create/change tsconfig structure - so need to ever evict the cache
// in the rare case that we do - just need to manually restart their IDE.
glob: 'Infinity',
},
},
rules: {
// make sure we're not leveraging any deprecated APIs
'deprecation/deprecation': 'error',

//
// our plugin :D
//
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowAny: true,
allowNullish: true,
allowRegExp: true,
},
],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
// we don't use classes enough in our codebase to warrant the numerous false positive against the TS API types etc
'@typescript-eslint/unbound-method': 'off',

//
// Internal repo rules
//

'@typescript-eslint/internal/no-poorly-typed-ts-props': 'error',
'@typescript-eslint/internal/no-typescript-default-import': 'error',
'@typescript-eslint/internal/prefer-ast-types-enum': 'error',
},
},
{
files: ['*.js'],
parserOptions: {
project: null,
},
},
// all test files
{
files: [
Expand Down
6 changes: 1 addition & 5 deletions nx.json
Expand Up @@ -24,11 +24,7 @@
"outputs": ["{projectRoot}/coverage"]
},
"lint": {
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.js",
"{workspaceRoot}/.eslintignore"
]
"inputs": ["default", "{workspaceRoot}/.eslintrc.js"]
}
},
"namedInputs": {
Expand Down
20 changes: 12 additions & 8 deletions package.json
Expand Up @@ -16,6 +16,7 @@
"armano2",
"Jed Fox"
],
"type": "commonjs",
"license": "BSD-2-Clause",
"repository": "typescript-eslint/typescript-eslint",
"bugs": {
Expand Down Expand Up @@ -123,13 +124,16 @@
"jest-snapshot": "^29",
"jest-util": "^29",
"pretty-format": "^29",
"@swc/core-android-arm-eabi": "npm:dummypkg-a@1.0.0",
"@swc/core-android-arm64": "npm:dummypkg-a@1.0.0",
"@swc/core-freebsd-x64": "npm:dummypkg-a@1.0.0",
"@swc/core-linux-arm-gnueabihf": "npm:dummypkg-a@1.0.0",
"@swc/core-linux-arm64-gnu": "npm:dummypkg-a@1.0.0",
"@swc/core-linux-arm64-musl": "npm:dummypkg-a@1.0.0",
"@swc/core-win32-arm64-msvc": "npm:dummypkg-a@1.0.0",
"@swc/core-win32-ia32-msvc": "npm:dummypkg-a@1.0.0"
"@swc/core-android-arm-eabi": "file:./tools/dummypkg",
"@swc/core-android-arm64": "file:./tools/dummypkg",
"@swc/core-freebsd-x64": "file:./tools/dummypkg",
"@swc/core-linux-arm-gnueabihf": "file:./tools/dummypkg",
"@swc/core-linux-arm64-gnu": "file:./tools/dummypkg",
"@swc/core-linux-arm64-musl": "file:./tools/dummypkg",
"@swc/core-win32-arm64-msvc": "file:./tools/dummypkg",
"@swc/core-win32-ia32-msvc": "file:./tools/dummypkg",
"@types/eslint": "file:./tools/dummypkg",
"@types/eslint-scope": "file:./tools/dummypkg",
"@types/estree": "file:./tools/dummypkg"
}
}
Expand Up @@ -14,5 +14,4 @@
*/

// We need to ignore this lint error regarding it being missing from the package.json, see above.
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line import/no-extraneous-dependencies
export { parse } from '@typescript-eslint/typescript-estree';
Expand Up @@ -528,7 +528,7 @@ export default createRule<Options, MessageIds>({
}

const typeString = checker.typeToString(type);
if (/^RunTests\b/.test(typeString)) {
if (/^(TSESLint\.)?RunTests\b/.test(typeString)) {
checkedObjects.add(node);

for (const prop of node.properties) {
Expand Down Expand Up @@ -558,12 +558,12 @@ export default createRule<Options, MessageIds>({
return;
}

if (/^ValidTestCase\b/.test(typeString)) {
if (/^(TSESLint\.)?ValidTestCase\b/.test(typeString)) {
checkInvalidTest(node);
return;
}

if (/^InvalidTestCase\b/.test(typeString)) {
if (/^(TSESLint\.)?InvalidTestCase\b/.test(typeString)) {
checkInvalidTest(node);
for (const testProp of node.properties) {
if (
Expand Down
34 changes: 23 additions & 11 deletions packages/eslint-plugin-tslint/package.json
@@ -1,24 +1,26 @@
{
"name": "@typescript-eslint/eslint-plugin-tslint",
"version": "5.51.0",
"main": "dist/index.js",
"typings": "src/index.ts",
"description": "ESLint plugin that wraps a TSLint configuration and lints the whole source using TSLint",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"tslint"
],
"engines": {
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"
},
"files": [
"dist",
"package.json",
"README.md",
"LICENSE"
],
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js"
},
"./package.json": {
"require": "./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",
Expand All @@ -28,6 +30,12 @@
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
},
"license": "MIT",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"tslint"
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
Expand All @@ -49,5 +57,9 @@
"devDependencies": {
"@types/lodash": "*",
"@typescript-eslint/parser": "5.51.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/typescript-eslint"
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 0 additions & 5 deletions packages/eslint-plugin-tslint/tests/tsconfig.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/eslint-plugin-tslint/tsconfig.build.json
@@ -1,6 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
// specifically disable declarations for the plugin
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"declaration": false,
"declarationMap": false,
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
Expand Down
6 changes: 5 additions & 1 deletion packages/eslint-plugin-tslint/tsconfig.json
Expand Up @@ -5,6 +5,10 @@
"rootDir": "."
},
"include": ["src", "tests"],
"exclude": ["tests/test-project", "tests/test-tslint-rules-directory"],
"exclude": [
"tests/fixture-project",
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
"tests/test-project",
"tests/test-tslint-rules-directory"
],
"references": [{ "path": "../utils/tsconfig.build.json" }]
}
9 changes: 7 additions & 2 deletions packages/eslint-plugin/index.d.ts
@@ -1,4 +1,9 @@
import type { TSESLint } from '@typescript-eslint/utils';

export const rules: Record<string, TSESLint.RuleModule<string, unknown[]>>;
export const configs: Record<string, TSESLint.Linter.Config>;
import type rules from './rules';

declare const cjsExport: {
configs: Record<string, TSESLint.Linter.Config>;
rules: typeof rules;
};
export = cjsExport;