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

Stricter typescript-eslint config #9110

Merged
merged 5 commits into from
Nov 16, 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
46 changes: 33 additions & 13 deletions config/eslint/typescript.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
function rules(config) {
return Object.assign(
{
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{
disallowTypeAnnotations: false,
},
],
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',
'@typescript-eslint/no-misused-promises': 'off',
'no-unused-vars': 'off',
'prefer-const': 'error',
'prefer-rest-params': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-meaningless-void-operator': 'error',
'@typescript-eslint/no-throw-literal': 'error',
// '@typescript-eslint/prefer-readonly-parameter-types': 'error',
// Many failures for these; they seem intentional so I don't want to just auto-fix:
// '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
// '@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/prefer-includes': 'error',
// Auto-fix changes the types in some of these cases, which didn't seem safe:
// '@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-return-this-type': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'prefer-const': 'error',
'prefer-rest-params': 'off',
},
config?.rules ?? {}
);
Expand All @@ -29,7 +49,7 @@ function plugins() {
}

function extend() {
return ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking'];
return ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-type-checked'];
}

function settings() {
Expand Down
2 changes: 1 addition & 1 deletion packages/active-record/src/-private/builders/-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type UrlOptions } from '@ember-data/request-utils';
import type { UrlOptions } from '@ember-data/request-utils';
import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core-types/request';

export function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@ember-data/request-utils';
import { recordIdentifierFor } from '@ember-data/store';
import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
import {
import type {
ConstrainedRequestOptions,
CreateRequestOptions,
DeleteRequestOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ import type {
AdapterPayload,
MinimumAdapterInterface,
} from '@ember-data/legacy-compat/legacy-network-handler/minimum-adapter-interface';
import { SerializerOptions } from '@ember-data/legacy-compat/legacy-network-handler/minimum-serializer-interface';
import type { SerializerOptions } from '@ember-data/legacy-compat/legacy-network-handler/minimum-serializer-interface';
import type Store from '@ember-data/store';
import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
import type { HTTPMethod } from '@warp-drive/core-types/request';

import { determineBodyPromise, fetch, parseResponseHeaders, serializeIntoHash, serializeQueryParams } from './-private';
import { MixtBuildURLMixin } from './-private/build-url-mixin';
import type { MixtBuildURLMixin } from './-private/build-url-mixin';
import type { FastBoot } from './-private/fastboot-interface';
import AdapterError, {
AbortError,
Expand Down
15 changes: 7 additions & 8 deletions packages/core-types/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* @module @ember-data/experimental-preview-types
*/
import { ResourceBlob } from './cache/aliases';
import { Change } from './cache/change';
import { Mutation } from './cache/mutations';
import { Operation } from './cache/operations';
import type { ResourceBlob } from './cache/aliases';
import type { Change } from './cache/change';
import type { Mutation } from './cache/mutations';
import type { Operation } from './cache/operations';
import type { CollectionRelationship, ResourceRelationship } from './cache/relationship';
import type { StableRecordIdentifier } from './identifier';
import { StableDocumentIdentifier } from './identifier';
import type { StableDocumentIdentifier, StableRecordIdentifier } from './identifier';
import type { Value } from './json/raw';
import type { RequestContext, StructuredDataDocument, StructuredDocument } from './request';
import { ResourceDocument, SingleResourceDataDocument } from './spec/document';
import { ApiError } from './spec/error';
import type { ResourceDocument, SingleResourceDataDocument } from './spec/document';
import type { ApiError } from './spec/error';

/**
* A hash of changed attributes with the key being the attribute name and the value being an
Expand Down
2 changes: 1 addition & 1 deletion packages/core-types/src/spec/raw.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@module @warp-drive/core-types
*/
import { ArrayValue, ObjectValue } from '../json/raw';
import type { ArrayValue, ObjectValue } from '../json/raw';

export type Meta = ObjectValue;
export type LinkObject = { href: string; meta?: Meta };
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/src/-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SuiteReport } from './-types/report';
import type { SuiteReport } from './-types/report';

export type CompatTestReport = {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/src/-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global window, globalThis, global, self */
import { GlobalHooksStorage, HooksCallback, ModuleInfo, TestContext } from './-types';
import type { GlobalHooksStorage, HooksCallback, ModuleInfo, TestContext } from './-types';

export function assert(message: string, test: unknown): asserts test {
if (!test) {
Expand Down
3 changes: 2 additions & 1 deletion packages/diagnostic/src/ember.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getTestMetadata, setupContext, SetupContextOptions, teardownContext, TestContext } from '@ember/test-helpers';
import type { SetupContextOptions, TestContext } from '@ember/test-helpers';
import { getTestMetadata, setupContext, teardownContext } from '@ember/test-helpers';

import AbstractTestLoader from 'ember-cli-test-loader/test-support/index';

Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/emitters/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompatTestReport, Emitter } from '../-types';
import { SuiteReport } from '../-types/report';
import type { CompatTestReport, Emitter } from '../-types';
import type { SuiteReport } from '../-types/report';
import { assert } from '../-utils';

type EmitEvent = {
Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/emitters/testem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompatTestReport, Emitter } from '../-types';
import { SuiteReport } from '../-types/report';
import type { CompatTestReport, Emitter } from '../-types';
import type { SuiteReport } from '../-types/report';
import { assert } from '../-utils';

type TestemSocket = {
Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModuleCallback, ModuleInfo, OrderedMap, TestCallback, TestContext, TestInfo } from './-types';
import { SuiteReport } from './-types/report';
import type { ModuleCallback, ModuleInfo, OrderedMap, TestCallback, TestContext, TestInfo } from './-types';
import type { SuiteReport } from './-types/report';
import { assert, generateHash } from './-utils';
import { Config, getCurrentModule, HooksDelegate, instrument, setCurrentModule } from './internals/config';
import { DelegatingReporter } from './internals/delegating-reporter';
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/src/internals/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Testem */
import {
import type {
GlobalCallback,
GlobalConfig,
GlobalHooks,
Expand Down
2 changes: 1 addition & 1 deletion packages/diagnostic/src/internals/delegating-reporter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reporter, SuiteReport } from '../-types/report';
import type { Reporter, SuiteReport } from '../-types/report';

const Reporters = new Set<Reporter>();
export function registerReporter(reporter: Reporter) {
Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/internals/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GlobalConfig, TestContext, TestInfo } from '../-types';
import { DiagnosticReport, Reporter, TestReport } from '../-types/report';
import type { GlobalConfig, TestContext, TestInfo } from '../-types';
import type { DiagnosticReport, Reporter, TestReport } from '../-types/report';
import equiv from '../legacy/equiv';

class InternalCompat<TC extends TestContext> {
Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/internals/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HooksCallback, ModuleInfo, TestContext, TestInfo } from '../-types';
import { ModuleReport, TestReport } from '../-types/report';
import type { HooksCallback, ModuleInfo, TestContext, TestInfo } from '../-types';
import type { ModuleReport, TestReport } from '../-types/report';
import { getChain } from '../-utils';
import { Config, groupLogs, instrument } from './config';
import { DelegatingReporter } from './delegating-reporter';
Expand Down
4 changes: 2 additions & 2 deletions packages/diagnostic/src/reporters/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompatTestReport, Emitter } from '../-types';
import { DiagnosticReport, ModuleReport, Reporter, SuiteReport, TestReport } from '../-types/report';
import type { CompatTestReport, Emitter } from '../-types';
import type { DiagnosticReport, ModuleReport, Reporter, SuiteReport, TestReport } from '../-types/report';
import { getSettings, updateConfigValue, updateSuiteState } from '../internals/config';

type SuiteLayout = {
Expand Down
3 changes: 2 additions & 1 deletion packages/diagnostic/src/runners/dom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { registerReporter, start as _start } from '../';
import type { Emitter } from '../-types';
import { assert, getGlobal } from '../-utils';
import { ConfigOptions, configure, getSettings } from '../internals/config';
import type { ConfigOptions } from '../internals/config';
import { configure, getSettings } from '../internals/config';
import { DOMReporter } from '../reporters/dom';

export async function start(config?: ConfigOptions) {
Expand Down
6 changes: 3 additions & 3 deletions packages/graph/src/-private/-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { StableRecordIdentifier } from '@warp-drive/core-types';
import { isBelongsTo } from './-utils';
import { assertPolymorphicType } from './debug/assert-polymorphic-type';
import type { CollectionEdge } from './edges/collection';
import { ResourceEdge } from './edges/resource';
import { Graph } from './graph';
import type { ResourceEdge } from './edges/resource';
import type { Graph } from './graph';
import replaceRelatedRecord from './operations/replace-related-record';
import replaceRelatedRecords from './operations/replace-related-records';

Expand All @@ -31,7 +31,7 @@ function _deprecatedCompare<T>(
const finalState: T[] = [];

for (let i = 0, j = 0; i < iterationLength; i++) {
let adv: boolean = false;
let adv = false;
let member: T | undefined;

// accumulate anything added
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/src/-private/-edge-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export function upgradeDefinition(
graph: Graph,
identifier: StableRecordIdentifier,
propertyName: string,
isImplicit: boolean = false
isImplicit = false
): EdgeDefinition | null {
const cache = graph._definitionCache;
const storeWrapper = graph.store;
Expand Down
4 changes: 2 additions & 2 deletions packages/graph/src/-private/-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { peekCache } from '@ember-data/store/-private';
import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { UpdateRelationshipOperation } from '@warp-drive/core-types/graph';
import { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';

import { UpgradedMeta } from './-edge-definition';
import type { UpgradedMeta } from './-edge-definition';
import { coerceId } from './coerce-id';
import type { CollectionEdge } from './edges/collection';
import type { ImplicitEdge } from './edges/implicit';
Expand Down
7 changes: 4 additions & 3 deletions packages/graph/src/-private/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert } from '@ember/debug';

import { LOG_GRAPH } from '@ember-data/debugging';
import { DEBUG } from '@ember-data/env';
import { MergeOperation } from '@ember-data/store/-types/q/cache';
import type { MergeOperation } from '@ember-data/store/-types/q/cache';
import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { RelationshipDiff } from '@warp-drive/core-types/cache';
Expand All @@ -29,7 +29,8 @@ import {
removeIdentifierCompletelyFromRelationship,
} from './-utils';
import { type CollectionEdge, createCollectionEdge, legacyGetCollectionRelationshipData } from './edges/collection';
import { createImplicitEdge, ImplicitEdge, ImplicitMeta } from './edges/implicit';
import type { ImplicitEdge, ImplicitMeta } from './edges/implicit';
import { createImplicitEdge } from './edges/implicit';
import { createResourceEdge, legacyGetResourceRelationshipData, type ResourceEdge } from './edges/resource';
import addToRelatedRecords from './operations/add-to-related-records';
import { mergeIdentifier } from './operations/merge-identifier';
Expand Down Expand Up @@ -421,7 +422,7 @@ export class Graph {
update(op: LocalRelationshipOperation, isRemote?: false): void;
update(
op: MergeOperation | LocalRelationshipOperation | RemoteRelationshipOperation | UnknownOperation,
isRemote: boolean = false
isRemote = false
): void {
assert(
`Cannot update an implicit relationship`,
Expand Down
6 changes: 3 additions & 3 deletions packages/graph/src/-private/operations/update-relationship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, warn } from '@ember/debug';

import { IdentifierCache } from '@ember-data/store/-private/caches/identifier-cache';
import type { IdentifierCache } from '@ember-data/store/-private/caches/identifier-cache';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { UpdateRelationshipOperation } from '@warp-drive/core-types/graph';
import type { ExistingResourceIdentifierObject, NewResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
Expand All @@ -21,8 +21,8 @@ export default function updateRelationshipOperation(graph: Graph, op: UpdateRela

const payload = op.value;

let hasRelationshipDataProperty: boolean = false;
let hasUpdatedLink: boolean = false;
let hasRelationshipDataProperty = false;
let hasUpdatedLink = false;

if (payload.meta) {
relationship.meta = payload.meta;
Expand Down
10 changes: 3 additions & 7 deletions packages/json-api/src/-private/builders/-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/**
* @module @ember-data/json-api/request
*/
import {
buildQueryParams as buildParams,
BuildURLConfig,
setBuildURLConfig as setConfig,
} from '@ember-data/request-utils';
import { type UrlOptions } from '@ember-data/request-utils';
import { QueryParamsSource } from '@warp-drive/core-types/params';
import type { BuildURLConfig, UrlOptions } from '@ember-data/request-utils';
import { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '@ember-data/request-utils';
import type { QueryParamsSource } from '@warp-drive/core-types/params';
import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core-types/request';

export interface JSONAPIConfig extends BuildURLConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/json-api/src/-private/builders/save-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@ember-data/request-utils';
import { recordIdentifierFor } from '@ember-data/store';
import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
import {
import type {
ConstrainedRequestOptions,
CreateRequestOptions,
DeleteRequestOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/json-api/src/-private/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
StableExistingRecordIdentifier,
StableRecordIdentifier,
} from '@warp-drive/core-types/identifier';
import { Value } from '@warp-drive/core-types/json/raw';
import type { Value } from '@warp-drive/core-types/json/raw';
import type {
StructuredDataDocument,
StructuredDocument,
Expand Down Expand Up @@ -1561,7 +1561,7 @@ function _isEmpty(peeked: CachedResource | undefined): boolean {
return (!isNew || isDeleted) && isEmpty;
}

function recordIsLoaded(cached: CachedResource | undefined, filterDeleted: boolean = false): boolean {
function recordIsLoaded(cached: CachedResource | undefined, filterDeleted = false): boolean {
if (!cached) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { CollectionResourceDocument, SingleResourceDocument } from '@warp-d
import { upgradeStore } from '../-private';
import { assertIdentifierHasId } from './identifier-has-id';
import { payloadIsNotBlank } from './legacy-data-utils';
import { AdapterPayload, MinimumAdapterInterface } from './minimum-adapter-interface';
import type { AdapterPayload, MinimumAdapterInterface } from './minimum-adapter-interface';
import type { MinimumSerializerInterface } from './minimum-serializer-interface';
import { normalizeResponseHelper } from './serializer-response';
import Snapshot from './snapshot';
Expand Down Expand Up @@ -585,13 +585,13 @@ function _flushPendingFetchForType(
_processCoalescedGroup(store, fetchMap, groups[i], adapter, modelName);
}
} else if (totalItems === 1) {
void _fetchRecord(store, adapter, pendingFetchItems[0]);
_fetchRecord(store, adapter, pendingFetchItems[0]);
}
}

pendingFetchMap.forEach((pendingFetchItems) => {
pendingFetchItems.forEach((pendingFetchItem) => {
void _fetchRecord(store, adapter, pendingFetchItem);
_fetchRecord(store, adapter, pendingFetchItem);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/-private/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Cache } from '@warp-drive/core-types/cache';

import type { ModelStore } from './model';
import Model from './model';
import type Model from './model';
import { getModelFactory } from './schema-provider';
import { normalizeModelName } from './util';

Expand Down
Loading
Loading