Skip to content

chore: enable consistent-indexed-object-style and lint #7353

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

Merged
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module.exports = {
'deprecation/deprecation': 'error',

// TODO(#7138): Investigate enabling these soon ✨
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',

// TODO(#7130): Investigate changing these in or removing these from presets
Expand Down
7 changes: 4 additions & 3 deletions packages/eslint-plugin/rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ This is likely not portable. A type annotation is necessary. ts(2742)

import type { RuleModule } from '@typescript-eslint/utils/ts-eslint';

export interface TypeScriptESLintRules {
[ruleName: string]: RuleModule<string, unknown[]>;
}
export type TypeScriptESLintRules = Record<
string,
RuleModule<string, unknown[]>
>;
declare const rules: TypeScriptESLintRules;
export default rules;
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default util.createRule<Options, MessageIds>({

create(context, [{ fixMixedExportsWithInlineTypeSpecifier }]) {
const sourceCode = context.getSourceCode();
const sourceExportsMap: { [key: string]: SourceExports } = {};
const sourceExportsMap: Record<string, SourceExports> = {};
const services = util.getParserServices(context);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default util.createRule<Options, MessageIds>({
const fixStyle = option.fixStyle ?? 'separate-type-imports';
const sourceCode = context.getSourceCode();

const sourceImportsMap: { [key: string]: SourceImports } = {};
const sourceImportsMap: Record<string, SourceImports> = {};

return {
...(prefer === 'type-imports'
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-plugin/tools/generate-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ async function main(): Promise<void> {

const prettierConfig = prettier.resolveConfig.sync(__dirname);

interface LinterConfigRules {
[name: string]: TSESLint.Linter.RuleLevel;
}
type LinterConfigRules = Record<string, TSESLint.Linter.RuleLevel>;

interface LinterConfig extends TSESLint.Linter.Config {
extends?: string[] | string;
Expand Down
4 changes: 1 addition & 3 deletions packages/rule-schema-to-typescript-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ function compileSchema(

const refMap = new Map<string, string>();
// we only support defs at the top level for simplicity
const defs = (schema.$defs ?? schema.definitions) as
| Record<string, JSONSchema4>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this one since schema.$defs and schema.definitions are both Record<string, JSONSchema4> | undefined;

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

| undefined;
const defs = schema.$defs ?? schema.definitions;
if (defs) {
for (const [defKey, defSchema] of Object.entries(defs)) {
const typeName = toPascalCase(defKey);
Expand Down
10 changes: 4 additions & 6 deletions packages/rule-tester/src/types/DependencyConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export type AtLeastVersionConstraint =
export type VersionConstraint =
| AtLeastVersionConstraint
| SemverVersionConstraint;
export interface DependencyConstraint {
/**
* Passing a string for the value is shorthand for a '>=' constraint
*/
readonly [packageName: string]: VersionConstraint;
}
/**
* Passing a string for the value is shorthand for a '>=' constraint
*/
export type DependencyConstraint = Readonly<Record<string, VersionConstraint>>;
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function parseWithNodeMapsInternal<T extends TSESTreeOptions = TSESTreeOptions>(
};
}

let parseAndGenerateServicesCalls: { [fileName: string]: number } = {};
let parseAndGenerateServicesCalls: Record<string, number> = {};
// Privately exported utility intended for use in typescript-eslint unit tests only
function clearParseAndGenerateServicesCalls(): void {
parseAndGenerateServicesCalls = {};
Expand Down
10 changes: 4 additions & 6 deletions packages/typescript-estree/src/simple-traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ type SimpleTraverseOptions = Readonly<
}
| {
visitorKeys?: Readonly<VisitorKeys>;
visitors: {
[key: string]: (
node: TSESTree.Node,
parent: TSESTree.Node | undefined,
) => void;
};
visitors: Record<
string,
(node: TSESTree.Node, parent: TSESTree.Node | undefined) => void
>;
}
>;

Expand Down
30 changes: 5 additions & 25 deletions packages/utils/src/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,11 @@ interface JSONSchema4Base {
/**
* Reusable definitions that can be referenced via `$ref`
*/
definitions?:
| {
[k: string]: JSONSchema4;
}
| undefined;
definitions?: Record<string, JSONSchema4> | undefined;
/**
* Reusable definitions that can be referenced via `$ref`
*/
$defs?:
| {
[k: string]: JSONSchema4;
}
| undefined;
$defs?: Record<string, JSONSchema4> | undefined;

/**
* The value of this property MUST be another schema which will provide
Expand Down Expand Up @@ -242,11 +234,7 @@ export interface JSONSchema4ObjectSchema extends JSONSchema4Base {
*
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.2
*/
properties?:
| {
[k: string]: JSONSchema4;
}
| undefined;
properties?: Record<string, JSONSchema4> | undefined;

/**
* This attribute is an object that defines the schema for a set of
Expand All @@ -259,22 +247,14 @@ export interface JSONSchema4ObjectSchema extends JSONSchema4Base {
*
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.3
*/
patternProperties?:
| {
[k: string]: JSONSchema4;
}
| undefined;
patternProperties?: Record<string, JSONSchema4> | undefined;

/**
* The `dependencies` keyword conditionally applies a sub-schema when a given
* property is present. This schema is applied in the same way `allOf` applies
* schemas. Nothing is merged or extended. Both schemas apply independently.
*/
dependencies?:
| {
[k: string]: JSONSchema4 | string[];
}
| undefined;
dependencies?: Record<string, JSONSchema4 | string[]> | undefined;

/**
* The maximum number of properties allowed for record-style schemas
Expand Down
10 changes: 3 additions & 7 deletions packages/utils/src/ts-eslint/CLIEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ declare class CLIEngineBase {
namespace CLIEngine {
export interface Options {
allowInlineConfig?: boolean;
baseConfig?: false | { [name: string]: unknown };
baseConfig?: false | Record<string, unknown>;
cache?: boolean;
cacheFile?: string;
cacheLocation?: string;
Expand All @@ -125,9 +125,7 @@ namespace CLIEngine {
parserOptions?: Linter.ParserOptions;
plugins?: string[];
resolvePluginsRelativeTo?: string;
rules?: {
[name: string]: Linter.RuleLevel | Linter.RuleLevelAndOptions;
};
rules?: Record<string, Linter.RuleLevel | Linter.RuleLevelAndOptions>;
rulePaths?: string[];
reportUnusedDisableDirectives?: boolean;
}
Expand Down Expand Up @@ -158,9 +156,7 @@ namespace CLIEngine {
}

export interface LintResultData<TMessageIds extends string> {
rulesMeta: {
[ruleId: string]: RuleMetaData<TMessageIds>;
};
rulesMeta: Record<string, RuleMetaData<TMessageIds>>;
}

export type Formatter = <TMessageIds extends string>(
Expand Down
8 changes: 2 additions & 6 deletions packages/utils/src/ts-eslint/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ namespace Linter {
export type GlobalVariableOptionBase = 'off' | 'readonly' | 'writable';
export type GlobalVariableOption = GlobalVariableOptionBase | boolean;

export interface GlobalsConfig {
[name: string]: GlobalVariableOption;
}
export interface EnvironmentConfig {
[name: string]: boolean;
}
export type GlobalsConfig = Record<string, GlobalVariableOption>;
export type EnvironmentConfig = Record<string, boolean>;

// https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js
interface BaseConfig {
Expand Down
8 changes: 2 additions & 6 deletions packages/utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ type ReportDescriptor<TMessageIds extends string> =
* Plugins can add their settings using declaration
* merging against this interface.
*/
interface SharedConfigurationSettings {
[name: string]: unknown;
}
type SharedConfigurationSettings = Record<string, unknown>;

interface RuleContext<
TMessageIds extends string,
Expand Down Expand Up @@ -428,9 +426,7 @@ interface RuleListenerBaseSelectors {
type RuleListenerExitSelectors = {
[K in keyof RuleListenerBaseSelectors as `${K}:exit`]: RuleListenerBaseSelectors[K];
};
interface RuleListenerCatchAllBaseCase {
[nodeSelector: string]: RuleFunction | undefined;
}
type RuleListenerCatchAllBaseCase = Record<string, RuleFunction | undefined>;
// Interface to merge into for anyone that wants to add more selectors
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface RuleListenerExtension {}
Expand Down
4 changes: 1 addition & 3 deletions packages/utils/src/ts-eslint/SourceCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ namespace SourceCode {
visitorKeys: VisitorKeys | null;
}

export interface VisitorKeys {
[nodeType: string]: string[];
}
export type VisitorKeys = Record<string, string[]>;

export type FilterPredicate = (token: TSESTree.Token) => boolean;
export type GetFilterPredicate<TFilter, TDefault> =
Expand Down
4 changes: 1 addition & 3 deletions packages/visitor-keys/src/visitor-keys.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
import * as eslintVisitorKeys from 'eslint-visitor-keys';

interface VisitorKeys {
readonly [type: string]: readonly string[] | undefined;
}
type VisitorKeys = Record<string, readonly string[] | undefined>;

type GetNodeTypeKeys<T extends AST_NODE_TYPES> = Exclude<
keyof Extract<TSESTree.Node, { type: T }>,
Expand Down