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

replace ts namespace imports with normal imports #21

Merged
merged 5 commits into from
Apr 27, 2023
Merged
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
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# prevent eslint from ignoring other config files
!.*.js
!.*.ts
!.*.ts

tests/fixtures
3,860 changes: 1,881 additions & 1,979 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build": "rimraf ./dist && tsc -p src/tsconfig.json",
"format:check": "prettier --check .",
"format:fix": "prettier --write .",
"test": "ts-mocha -p tsconfig.json tests/**/*.ts --timeout 10000",
"test": "tsc && ts-mocha -p tsconfig.json tests/**/*.ts --timeout 10000",
"check": "npm run build && npm run lint:check && npm run lint:eslint-docs && npm run format:check && npm run test",
"update:eslint-docs": "npm run build && eslint-doc-generator"
},
Expand Down
4 changes: 2 additions & 2 deletions src/rules/require-variance-annotations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRule } from '../utils'
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils'
import * as tsutils from 'tsutils'
import ts from 'typescript'
import { ObjectFlags } from 'typescript'

export default createRule({
create: (context) => ({
Expand All @@ -27,7 +27,7 @@ export default createRule({
: checker.getTypeFromTypeNode(originalNode.type)
if (
tsutils.isObjectType(nodeType) &&
nodeType.objectFlags & (ts.ObjectFlags.Anonymous | ts.ObjectFlags.Mapped)
nodeType.objectFlags & (ObjectFlags.Anonymous | ObjectFlags.Mapped)
) {
context.report({
messageId: 'requireVarianceAnnotation',
Expand Down
15 changes: 3 additions & 12 deletions src/rules/suggestions-as-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ import { ESLintUtils, TSESTree } from '@typescript-eslint/utils'
import os from 'os'
import path from 'path'
import { throwIfUndefined } from 'throw-expression'
import ts from 'typescript'
import { CancellationToken, DiagnosticWithLocation, computeSuggestionDiagnostics } from 'typescript'

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- internal function that they tried to hide from me, also can't augment namespaces :(
const computeSuggestionDiagnostics: (
sourceFile: ts.SourceFile,
program: ts.Program,
cancellationToken: ts.CancellationToken,
) => ts.DiagnosticWithLocation[] =
// @ts-expect-error see comment above
ts.computeSuggestionDiagnostics

const cancellationToken: ts.CancellationToken = {
const cancellationToken: CancellationToken = {
isCancellationRequested: () => false,
throwIfCancellationRequested: () => undefined,
}

const getPosition = (location: ts.DiagnosticWithLocation): TSESTree.Position => {
const getPosition = (location: DiagnosticWithLocation): TSESTree.Position => {
const lines = location.file.text.substring(0, location.start).split(/\r\n|\r|\n/u)
return {
line: lines.length,
Expand Down
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"noEmit": false,
"outDir": "../dist"
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "../types"]
}
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
// TODO: raise issues for this
// https://github.com/typescript-eslint/typescript-eslint/issues/6965
// https://github.com/ajafff/tsutils/issues/151
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,

Expand All @@ -76,5 +77,6 @@
"stripInternal": false, //https://github.com/microsoft/TypeScript/issues/45307
"resolveJsonModule": true
},
"include": ["jest.config.ts", "*.*.js", "tests"]
"include": ["jest.config.ts", "*.*.js", "tests", "types"],
"exclude": ["tests/fixtures"]
}
10 changes: 10 additions & 0 deletions types/typescript.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://github.com/microsoft/TypeScript/issues/54042
import { CancellationToken, DiagnosticWithLocation, Program, SourceFile } from 'typescript'

declare module 'typescript' {
export const computeSuggestionDiagnostics: (
sourceFile: SourceFile,
program: Program,
cancellationToken: CancellationToken,
) => DiagnosticWithLocation[]
}