Skip to content

Commit

Permalink
chore: cleanup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Oct 11, 2021
1 parent 82016f9 commit 09c47b0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 33 deletions.
@@ -1,12 +1,12 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { Identifier } from '../../expression/Identifier/spec';
import type { Expression } from '../../unions/Expression';
import type { StringLiteral } from '../../expression/literal/StringLiteral/spec';
import type { ExportKind } from '../ExportAndImportKind';

export interface ExportAllDeclaration extends BaseNode {
type: AST_NODE_TYPES.ExportAllDeclaration;
source: Expression | null;
source: StringLiteral | null;
exportKind: ExportKind;
exported: Identifier | null;
}
@@ -1,14 +1,14 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { StringLiteral } from '../../expression/literal/StringLiteral/spec';
import type { ExportSpecifier } from '../../special/ExportSpecifier/spec';
import type { ExportDeclaration } from '../../unions/ExportDeclaration';
import type { Literal } from '../../unions/Literal';
import type { ExportKind } from '../ExportAndImportKind';

export interface ExportNamedDeclaration extends BaseNode {
type: AST_NODE_TYPES.ExportNamedDeclaration;
declaration: ExportDeclaration | null;
specifiers: ExportSpecifier[];
source: Literal | null;
source: StringLiteral | null;
exportKind: ExportKind;
}
4 changes: 2 additions & 2 deletions packages/ast-spec/src/declaration/ImportDeclaration/spec.ts
@@ -1,12 +1,12 @@
import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { BaseNode } from '../../base/BaseNode';
import type { StringLiteral } from '../../expression/literal/StringLiteral/spec';
import type { ImportClause } from '../../unions/ImportClause';
import type { Literal } from '../../unions/Literal';
import type { ImportKind } from '../ExportAndImportKind';

export interface ImportDeclaration extends BaseNode {
type: AST_NODE_TYPES.ImportDeclaration;
source: Literal;
source: StringLiteral;
specifiers: ImportClause[];
importKind: ImportKind;
}
Expand Up @@ -107,7 +107,7 @@ export default util.createRule<Options, MessageIds>({
? {
// prefer type imports
ImportDeclaration(node: TSESTree.ImportDeclaration): void {
const source = node.source.value as string;
const source = node.source.value;
const sourceImports =
sourceImportsMap[source] ??
(sourceImportsMap[source] = {
Expand Down
Expand Up @@ -39,16 +39,15 @@ export default util.createRule({
docs: {
description:
'Disallows using a non-null assertion in the left operand of the nullish coalescing operator',
category: 'Possible Errors',
recommended: false,
suggestion: true,
},
messages: {
noNonNullAssertedNullishCoalescing:
'The nullish coalescing operator is designed to handle undefined and null - using a non-null assertion is not needed.',
suggestRemovingNonNull: 'Remove the non-null assertion.',
},
schema: [],
hasSuggestions: true,
},
defaultOptions: [],
create(context) {
Expand Down
23 changes: 10 additions & 13 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
@@ -1,16 +1,19 @@
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
import baseRule, {
import { TSESTree } from '@typescript-eslint/experimental-utils';
import {
ArrayOfStringOrObject,
ArrayOfStringOrObjectPatterns,
} from 'eslint/lib/rules/no-restricted-imports';
import ignore, { Ignore } from 'ignore';
import { getESLintCoreRule } from '../util/getESLintCoreRule';
import {
createRule,
deepMerge,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../util';

const baseRule = getESLintCoreRule('no-restricted-imports');

export type Options = InferOptionsTypeFromRule<typeof baseRule>;
export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;

Expand Down Expand Up @@ -106,7 +109,6 @@ export default createRule<Options, MessageIds>({
type: 'suggestion',
docs: {
description: 'Disallow specified modules when loaded by `import`',
category: 'Best Practices',
recommended: false,
extendsBaseRule: true,
},
Expand Down Expand Up @@ -155,9 +157,6 @@ export default createRule<Options, MessageIds>({

return {
ImportDeclaration(node): void {
if (typeof node.source.value !== 'string') {
return;
}
if (node.importKind === 'type') {
const importSource = node.source.value.trim();
if (
Expand All @@ -170,13 +169,11 @@ export default createRule<Options, MessageIds>({
return rules.ImportDeclaration(node);
}
},
ExportNamedDeclaration(node): void {
if (
node.source?.type !== AST_NODE_TYPES.Literal ||
typeof node.source.value !== 'string'
) {
return;
}
'ExportNamedDeclaration[source]'(
node: TSESTree.ExportNamedDeclaration & {
source: NonNullable<TSESTree.ExportNamedDeclaration['source']>;
},
): void {
if (node.exportKind === 'type') {
const importSource = node.source.value.trim();
if (
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/util/getESLintCoreRule.ts
Expand Up @@ -24,6 +24,7 @@ interface RuleMap {
'no-loop-func': typeof import('eslint/lib/rules/no-loop-func');
'no-loss-of-precision': typeof import('eslint/lib/rules/no-loss-of-precision');
'no-magic-numbers': typeof import('eslint/lib/rules/no-magic-numbers');
'no-restricted-imports': typeof import('eslint/lib/rules/no-restricted-imports');
'no-undef': typeof import('eslint/lib/rules/no-undef');
'no-unused-expressions': typeof import('eslint/lib/rules/no-unused-expressions');
'no-useless-constructor': typeof import('eslint/lib/rules/no-useless-constructor');
Expand Down
Expand Up @@ -217,14 +217,6 @@ ruleTester.run('no-restricted-imports', rule, {
code: "export * from 'foo';",
options: ['import1'],
},
{
code: 'export { foo } from foo;',
options: ['import1', 'import2'],
},
{
code: 'import { foo } from foo;',
options: ['import1', 'import2'],
},
],
invalid: [
{
Expand Down
10 changes: 7 additions & 3 deletions tests/jest-resolver.js
@@ -1,12 +1,16 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
// https://github.com/facebook/jest/issues/9771#issuecomment-871585234
/* @ts-check */

// temporary workaround while we wait for https://github.com/facebook/jest/issues/9771
// temporary workaround - https://github.com/facebook/jest/issues/9771#issuecomment-871585234
const resolver = require('enhanced-resolve').create.sync({
conditionNames: ['require', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts', '.tsx'],
});

/**
* @param request {unknown}
* @param options {{ defaultResolver(...args: unknown[]): unknown, basedir: unknown }}
* @returns {unknown}
*/
module.exports = function (request, options) {
// list global module that must be resolved by defaultResolver here
if (['fs', 'http', 'path'].includes(request)) {
Expand Down

0 comments on commit 09c47b0

Please sign in to comment.