Skip to content

Commit

Permalink
Merge branch 'master' into arraytype/message
Browse files Browse the repository at this point in the history
  • Loading branch information
koooge committed Nov 1, 2021
2 parents 4c7aaf9 + 6af7ca7 commit ca1b09f
Show file tree
Hide file tree
Showing 66 changed files with 665 additions and 768 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Expand Up @@ -22,8 +22,8 @@ module.exports = {
sourceType: 'module',
project: [
'./tsconfig.eslint.json',
'./tests/integration/utils/jsconfig.json',
'./packages/*/tsconfig.json',
'./tests/integration/tsconfig.json',
],
allowAutomaticSingleRunInference: true,
tsconfigRootDir: __dirname,
Expand Down Expand Up @@ -175,12 +175,16 @@ module.exports = {
'packages/*/tests/**/spec.ts',
'packages/*/tests/**/test.ts',
'packages/parser/tests/**/*.ts',
'tests/integration/**/*.test.ts',
'tests/integration/integration-test-base.ts',
'tests/integration/pack-packages.ts',
],
env: {
'jest/globals': true,
},
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'eslint-plugin/no-identical-tests': 'error',
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/ci.yml
Expand Up @@ -343,46 +343,3 @@ jobs:
run: npx lerna publish --loglevel=verbose --canary --exact --force-publish --yes
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish_canary_version_v5:
name: Publish the latest code as a canary version
runs-on: ubuntu-latest
needs: [typecheck, test_on_primary_node_version, unit_tests_on_other_node_versions, linting_and_style, integration_tests]
if: github.repository == 'typescript-eslint/typescript-eslint' && github.ref == 'refs/heads/v5'
steps:
- uses: actions/checkout@v2
# Fetch all history for all tags and branches in this job because lerna needs it
- run: |
git fetch --prune --unshallow
- name: Use Node.js ${{ env.PRIMARY_NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}
registry-url: https://registry.npmjs.org/

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: |
yarn --ignore-engines --frozen-lockfile --ignore-scripts
yarn check-clean-workspace-after-install
- name: Build
run: |
yarn build
- name: Publish all packages to npm
run: npx lerna publish premajor --loglevel=verbose --canary --exact --force-publish --yes --dist-tag rc-v5
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -30,6 +30,8 @@ Please refrain from commenting on `master` commits. Commit comments are not sear

## Pull Requests

> With the exception of extremely minor documentation typos, **only send pull requests that resolve open issues**.
Anyone is free to help us build and maintain this project. If you see an issue that needs working on because it's important to you, comment on the issue to help make sure that nobody else works on it at the same time, and then start working.

Developing in this repo is easy:
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,7 @@
"pre-commit": "yarn lint-staged",
"pre-push": "yarn check-format",
"test": "nx run-many --target=test --all --parallel",
"test-integration": "./tests/integration/run-all-tests.sh",
"test-integration": "yarn jest -c ./tests/integration/jest.config.js",
"test-kill-integration-containers": "docker-compose -f tests/integration/docker-compose.yml down -v --rmi local",
"typecheck": "nx run-many --target=typecheck --all --parallel"
},
Expand Down Expand Up @@ -90,6 +90,7 @@
"@types/jest-specific-snapshot": "^0.5.5",
"@types/lodash": "^4.14.176",
"@types/marked": "^3.0.2",
"@types/ncp": "^2.0.5",
"@types/node": "^16.11.4",
"@types/prettier": "^2.3.2",
"@types/rimraf": "^3.0.2",
Expand All @@ -114,10 +115,12 @@
"lint-staged": "^11.1.2",
"make-dir": "^3.1.0",
"markdownlint-cli": "^0.29.0",
"ncp": "^2.0.0",
"node-fetch": "^3.0.0",
"prettier": "2.4.1",
"pretty-format": "^27.3.1",
"rimraf": "^3.0.2",
"tmp": "^0.2.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.4.0",
"tslint": "^6.1.3",
Expand Down
Expand Up @@ -59,7 +59,7 @@ interface T {
}
```

Examples of **correct** code with `interface` option.
Examples of **correct** code with `type` option.

```ts
type T = { x: number };
Expand Down
Expand Up @@ -336,7 +336,10 @@ export default util.createRule<Options, MessageIds>({
return;

case AST_NODE_TYPES.PropertyDefinition:
if (node.accessibility === 'private') {
if (
node.accessibility === 'private' ||
node.key.type === AST_NODE_TYPES.PrivateIdentifier
) {
return;
}
return checkNode(node.value);
Expand All @@ -353,7 +356,10 @@ export default util.createRule<Options, MessageIds>({

case AST_NODE_TYPES.MethodDefinition:
case AST_NODE_TYPES.TSAbstractMethodDefinition:
if (node.accessibility === 'private') {
if (
node.accessibility === 'private' ||
node.key.type === AST_NODE_TYPES.PrivateIdentifier
) {
return;
}
return checkNode(node.value);
Expand Down
49 changes: 47 additions & 2 deletions packages/eslint-plugin/src/rules/no-shadow.ts
Expand Up @@ -94,10 +94,10 @@ export default util.createRule<Options, MessageIds>({
}

function isTypeImport(
definition: Definition,
definition?: Definition,
): definition is ImportBindingDefinition {
return (
definition.type === DefinitionType.ImportBinding &&
definition?.type === DefinitionType.ImportBinding &&
definition.parent.importKind === 'type'
);
}
Expand Down Expand Up @@ -224,6 +224,47 @@ export default util.createRule<Options, MessageIds>({
);
}

function isImportDeclaration(
definition:
| TSESTree.ImportDeclaration
| TSESTree.TSImportEqualsDeclaration,
): definition is TSESTree.ImportDeclaration {
return definition.type === AST_NODE_TYPES.ImportDeclaration;
}

function isExternalModuleDeclarationWithName(
scope: TSESLint.Scope.Scope,
name: string,
): boolean {
return (
scope.type === ScopeType.tsModule &&
scope.block.type === AST_NODE_TYPES.TSModuleDeclaration &&
scope.block.id.type === AST_NODE_TYPES.Literal &&
scope.block.id.value === name
);
}

function isExternalDeclarationMerging(
scope: TSESLint.Scope.Scope,
variable: TSESLint.Scope.Variable,
shadowed: TSESLint.Scope.Variable,
): boolean {
const [firstDefinition] = shadowed.defs;
const [secondDefinition] = variable.defs;

return (
isTypeImport(firstDefinition) &&
isImportDeclaration(firstDefinition.parent) &&
isExternalModuleDeclarationWithName(
scope,
firstDefinition.parent.source.value,
) &&
secondDefinition.node.type === AST_NODE_TYPES.TSInterfaceDeclaration &&
secondDefinition.node.parent?.type ===
AST_NODE_TYPES.ExportNamedDeclaration
);
}

/**
* Check if variable name is allowed.
* @param variable The variable to check.
Expand Down Expand Up @@ -403,6 +444,10 @@ export default util.createRule<Options, MessageIds>({
continue;
}

if (isExternalDeclarationMerging(scope, variable, shadowed)) {
continue;
}

const isESLintGlobal = 'writeable' in shadowed;
if (
(shadowed.identifiers.length > 0 ||
Expand Down
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/util/isTypeReadonly.ts
Expand Up @@ -185,8 +185,10 @@ function isTypeReadonlyRecurser(

if (isUnionType(type)) {
// all types in the union must be readonly
const result = unionTypeParts(type).every(t =>
isTypeReadonlyRecurser(checker, t, options, seenTypes),
const result = unionTypeParts(type).every(
t =>
seenTypes.has(t) ||
isTypeReadonlyRecurser(checker, t, options, seenTypes),
);
const readonlyness = result ? Readonlyness.Readonly : Readonlyness.Mutable;
return readonlyness;
Expand Down
Expand Up @@ -82,6 +82,16 @@ export class Test {
}
`,
},
`
export class PrivateProperty {
#property = () => null;
}
`,
`
export class PrivateMethod {
#method() {}
}
`,
{
// https://github.com/typescript-eslint/typescript-eslint/issues/2150
code: `
Expand Down
87 changes: 87 additions & 0 deletions packages/eslint-plugin/tests/rules/no-shadow.test.ts
Expand Up @@ -51,6 +51,15 @@ class Foo {
}
interface Foo {
prop2: string;
}
`,
`
import type { Foo } from 'bar';
declare module 'bar' {
export interface Foo {
x: string;
}
}
`,
// type value shadowing
Expand Down Expand Up @@ -1442,5 +1451,83 @@ function doThing(foo: number, bar: number) {}
},
],
},
{
code: `
interface Foo {}
declare module 'bar' {
export interface Foo {
x: string;
}
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 20,
},
],
},
{
code: `
import type { Foo } from 'bar';
declare module 'baz' {
export interface Foo {
x: string;
}
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 20,
},
],
},
{
code: `
import type { Foo } from 'bar';
declare module 'bar' {
export type Foo = string;
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 15,
},
],
},
{
code: `
import type { Foo } from 'bar';
declare module 'bar' {
interface Foo {
x: string;
}
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 13,
},
],
},
],
});
Expand Up @@ -280,13 +280,23 @@ ruleTester.run('prefer-readonly-parameter-types', rule, {
`, // TSMethodSignature

// https://github.com/typescript-eslint/typescript-eslint/issues/1665
// directly recursive
// directly recursive interface
`
interface Foo {
readonly prop: Foo;
}
function foo(arg: Foo) {}
`,

// https://github.com/typescript-eslint/typescript-eslint/issues/3396
// directly recursive union type
`
type MyType = string | readonly MyType[];
function foo<A extends MyType[]>(a: A): MyType[] {
return [];
}
`,
// indirectly recursive
`
interface Foo {
Expand Down

0 comments on commit ca1b09f

Please sign in to comment.