Skip to content

Commit

Permalink
Add type import/export lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gitKrystan committed Nov 16, 2023
1 parent 93c38f4 commit c35ac8a
Show file tree
Hide file tree
Showing 62 changed files with 126 additions and 108 deletions.
11 changes: 11 additions & 0 deletions config/eslint/typescript.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ function rules(config) {
{
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/ban-ts-comment': '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',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': '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',
Expand All @@ -29,6 +37,9 @@ function rules(config) {
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-return-this-type': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
// Doesn't work properly with type imports
// 'import/no-duplicates': 'off',
// 'no-duplicate-imports': 'error',
'prefer-const': 'error',
'prefer-rest-params': 'off',
},
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
4 changes: 2 additions & 2 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 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
5 changes: 3 additions & 2 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
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 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
2 changes: 1 addition & 1 deletion 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
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
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
4 changes: 2 additions & 2 deletions packages/model/src/-private/many-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
recordIdentifierFor,
SOURCE,
} from '@ember-data/store/-private';
import { IdentifierArrayCreateOptions } from '@ember-data/store/-private/record-arrays/identifier-array';
import type { IdentifierArrayCreateOptions } from '@ember-data/store/-private/record-arrays/identifier-array';
import type { CreateRecordProperties } from '@ember-data/store/-private/store-service';
import type { Cache } from '@ember-data/store/-types/q/cache';
import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
Expand All @@ -21,7 +21,7 @@ import type { FindOptions } from '@ember-data/store/-types/q/store';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Links, PaginationLinks } from '@warp-drive/core-types/spec/raw';

import { LegacySupport } from './legacy-relationships-support';
import type { LegacySupport } from './legacy-relationships-support';

export interface ManyArrayCreateArgs {
identifiers: StableRecordIdentifier[];
Expand Down
7 changes: 4 additions & 3 deletions packages/model/src/-private/model-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { assert } from '@ember/debug';
import { importSync } from '@embroider/macros';

import { upgradeStore } from '@ember-data/legacy-compat/-private';
import Store, { recordIdentifierFor } from '@ember-data/store';
import type Store from '@ember-data/store';
import { recordIdentifierFor } from '@ember-data/store';
import { peekCache } from '@ember-data/store/-private';
import { RecordStore } from '@warp-drive/core-types/symbols';

import Errors from './errors';
import type Errors from './errors';
import { lookupLegacySupport } from './legacy-relationships-support';
import RecordState from './record-state';
import type RecordState from './record-state';

export interface MinimalLegacyRecord {
errors: Errors;
Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/-private/notify-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cacheFor } from '@ember/object/internals';
import type Store from '@ember-data/store';
import type { NotificationType } from '@ember-data/store/-private/managers/notification-manager';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import { RelationshipSchema } from '@warp-drive/core-types/schema';
import type { RelationshipSchema } from '@warp-drive/core-types/schema';

import { LEGACY_SUPPORT } from './legacy-relationships-support';
import type Model from './model';
Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/-private/promise-belongs-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type Store from '@ember-data/store';
import type { RecordInstance } from '@ember-data/store/-types/q/record-instance';
import { cached } from '@ember-data/tracking';

import { LegacySupport } from './legacy-relationships-support';
import type { LegacySupport } from './legacy-relationships-support';
import { PromiseObject } from './promise-proxy-base';
import type BelongsToReference from './references/belongs-to';

Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/-private/promise-many-array.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from '@ember/debug';

import { DEPRECATE_COMPUTED_CHAINS } from '@ember-data/deprecations';
import { FindOptions } from '@ember-data/store/-types/q/store';
import type { FindOptions } from '@ember-data/store/-types/q/store';
import { compat } from '@ember-data/tracking';
import { defineSignal } from '@ember-data/tracking/-private';

Expand Down
3 changes: 2 additions & 1 deletion packages/model/src/-private/references/belongs-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import type {
} from '@warp-drive/core-types/spec/raw';

import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
import { areAllInverseRecordsLoaded, LEGACY_SUPPORT, LegacySupport } from '../legacy-relationships-support';
import type { LegacySupport } from '../legacy-relationships-support';
import { areAllInverseRecordsLoaded, LEGACY_SUPPORT } from '../legacy-relationships-support';

/**
@module @ember-data/model
Expand Down
3 changes: 2 additions & 1 deletion packages/model/src/-private/references/has-many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import type {
} from '@warp-drive/core-types/spec/raw';

import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
import { areAllInverseRecordsLoaded, LEGACY_SUPPORT, LegacySupport } from '../legacy-relationships-support';
import type { LegacySupport } from '../legacy-relationships-support';
import { areAllInverseRecordsLoaded, LEGACY_SUPPORT } from '../legacy-relationships-support';
import type ManyArray from '../many-array';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/-private/schema-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RecordIdentifier } from '@warp-drive/core-types/identifier';
import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema';

import type { FactoryCache, ModelFactory, ModelStore } from './model';
import Model from './model';
import type Model from './model';
import _modelForMixin from './model-for-mixin';
import { normalizeModelName } from './util';

Expand Down
Loading

0 comments on commit c35ac8a

Please sign in to comment.