Skip to content

Commit

Permalink
chore: enabled no-unsafe-member-access internally (#3483)
Browse files Browse the repository at this point in the history
* chore: enabled no-unsafe-member-access internally

* Update packages/scope-manager/tests/util/serializers/TSESTreeNode.ts

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* fix: missing import

* fix: one last lint disable

* Update convert.ts

* Update .eslintrc.js

* Update .eslintrc.js

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
Josh Goldberg and bradzacher committed Aug 1, 2021
1 parent ddb11ac commit 3db6532
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.js
Expand Up @@ -65,7 +65,6 @@ module.exports = {
],

// TODO - enable these new recommended rules
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
// TODO - enable this
'@typescript-eslint/naming-convention': 'off',
Expand Down Expand Up @@ -163,15 +162,18 @@ module.exports = {
// all test files
{
files: [
'packages/*/tests/**/*.test.ts',
'packages/*/tests/**/*.spec.ts',
'packages/*/tests/**/*.test.ts',
'packages/*/tests/**/spec.ts',
'packages/*/tests/**/test.ts',
'packages/parser/tests/**/*.ts',
],
env: {
'jest/globals': true,
},
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'eslint-plugin/no-identical-tests': 'error',
'jest/no-disabled-tests': 'warn',
Expand All @@ -198,6 +200,7 @@ module.exports = {
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/util/createRule.ts
@@ -1,7 +1,7 @@
import { ESLintUtils } from '@typescript-eslint/experimental-utils';

// 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
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const version: string = require('../../package.json').version;

export const createRule = ESLintUtils.RuleCreator(
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental-utils/src/eslint-utils/RuleTester.ts
Expand Up @@ -32,7 +32,7 @@ class RuleTester extends TSESLint.RuleTester {
try {
// instead of creating a hard dependency, just use a soft require
// a bit weird, but if they're using this tooling, it'll be installed
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
require(parser).clearCaches();
} catch {
// ignored
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/index.ts
Expand Up @@ -6,5 +6,5 @@ export {
} from '@typescript-eslint/typescript-estree';

// 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
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
export const version: string = require('../package.json').version;
4 changes: 2 additions & 2 deletions packages/scope-manager/tests/util/serializers/TSESTreeNode.ts
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
import { NewPlugin } from 'pretty-format';
import { createIdGenerator } from '../../../src/ID';

Expand All @@ -24,7 +24,7 @@ const serializer: NewPlugin = {
// make sure it's not one of the classes from the package
Object.getPrototypeOf(val) === Object.prototype &&
'type' in val &&
val.type in AST_NODE_TYPES
(val as TSESTree.Node).type in AST_NODE_TYPES
);
},
serialize(node: Node): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/convert.ts
@@ -1,5 +1,5 @@
// There's lots of funny stuff due to the typing of ts.Node
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access */
import * as ts from 'typescript';
import {
canContainDirective,
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/index.ts
Expand Up @@ -9,5 +9,5 @@ export { createProgramFromConfigFile as createProgram } from './create-program/u
export { visitorKeys } from '@typescript-eslint/visitor-keys';

// 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
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
export const version: string = require('../package.json').version;
3 changes: 1 addition & 2 deletions packages/typescript-estree/src/node-utils.ts
Expand Up @@ -632,8 +632,7 @@ export function nodeHasTokens(n: ts.Node, ast: ts.SourceFile): boolean {
// If we have a token or node that has a non-zero width, it must have tokens.
// Note: getWidth() does not take trivia into account.
return n.kind === SyntaxKind.EndOfFileToken
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
!!(n as any).jsDoc
? !!(n as ts.JSDocContainer).jsDoc
: n.getWidth(ast) !== 0;
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ export function getFirstSemanticOrSyntacticError(
* and log a a warning.
*/
/* istanbul ignore next */
console.warn(`Warning From TSC: "${e.message}`); // eslint-disable-line no-console
console.warn(`Warning From TSC: "${(e as Error).message}`); // eslint-disable-line no-console
/* istanbul ignore next */
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/simple-traverse.ts
Expand Up @@ -3,6 +3,7 @@ import { TSESTree } from './ts-estree';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isValidNode(x: any): x is TSESTree.Node {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return x !== null && typeof x === 'object' && typeof x.type === 'string';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/tests/ast-alignment/parse.ts
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */

import type babelParser from '@babel/parser';
import { ParserPlugin } from '@babel/parser';
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/tests/ast-alignment/utils.ts
@@ -1,5 +1,5 @@
// babel types are something we don't really care about
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-plus-operands */
import { AST_NODE_TYPES, TSESTree } from '../../src/ts-estree';
import { deeplyCopy, omitDeep } from '../../tools/test-utils';
import * as BabelTypes from '@babel/types';
Expand Down
6 changes: 5 additions & 1 deletion packages/typescript-estree/typings/typescript.d.ts
@@ -1,9 +1,13 @@
import 'typescript';

// these additions are marked as internal to typescript
declare module 'typescript' {
interface SourceFile {
// this is marked as internal to typescript
externalModuleIndicator?: Node;
parseDiagnostics: DiagnosticWithLocation[];
}

interface JSDocContainer {
jsDoc?: JSDoc[];
}
}

0 comments on commit 3db6532

Please sign in to comment.