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

chore: import type lint rule and fixes #1039

Merged
merged 3 commits into from
Oct 16, 2024
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
115 changes: 53 additions & 62 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,54 @@
{
"env": {
"browser": true,
"es2021": true
},
"ignorePatterns": ["**/dist/**/*"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:jsdoc/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"check-file",
"jsdoc"
],
"rules": {
"jsdoc/require-jsdoc": [
"warn",
{
"publicOnly": true
}
],
"jsdoc/check-tag-names": [
"warn",
{
"definedTags": [
"experimental"
]
}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": [
"error",
"always"
],
"check-file/filename-naming-convention": [
"error",
{
"**/*.{js,ts}": "KEBAB_CASE"
},
{
"ignoreMiddleExtensions": true
}
]
}
}
"env": {
"browser": true,
"es2021": true
},
"ignorePatterns": ["**/dist/**/*"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier", "plugin:jsdoc/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "check-file", "jsdoc"],
"rules": {
toddbaert marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/consistent-type-imports": [
"error",
{
"disallowTypeAnnotations": true,
Copy link
Member Author

Choose a reason for hiding this comment

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

There's an alternative to this which adds type to each individual import... this adds type to the entire import line. I don't care which we use.

"fixStyle": "separate-type-imports",
"prefer": "type-imports"
}
],
"jsdoc/require-jsdoc": [
"warn",
{
"publicOnly": true
}
],
"jsdoc/check-tag-names": [
"warn",
{
"definedTags": ["experimental"]
}
],
"linebreak-style": ["error", "unix"],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": ["error", "always"],
"check-file/filename-naming-convention": [
"error",
{
"**/*.{js,ts}": "KEBAB_CASE"
},
{
"ignoreMiddleExtensions": true
}
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"e2e-web": "git submodule update --init --recursive && shx cp test-harness/features/evaluation.feature packages/web/e2e/features && jest --selectProjects=web-e2e --verbose",
"e2e": "npm run e2e-server && npm run e2e-web",
"lint": "npm run lint --workspace=packages/shared --workspace=packages/server --workspace=packages/web --workspace=packages/react --workspace=packages/angular --workspace=packages/nest",
"lint:fix": "npm run lint:fix --workspace=packages/shared --workspace=packages/server --workspace=packages/web --workspace=packages/react --workspace=packages/angular --workspace=packages/nest",
"clean": "shx rm -rf ./dist",
"build": "npm run build --workspace=packages/shared --workspace=packages/server --workspace=packages/web --workspace=packages/react --workspace=packages/angular --workspace=packages/nest",
"publish-all": "npm run publish-if-not-exists --workspace=packages/shared --workspace=packages/server --workspace=packages/web --workspace=packages/react --workspace=packages/angular --workspace=packages/nest",
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"cli": {
"schematicCollections": [
"@angular-eslint/schematics"
]
],
"analytics": false
}
}
1 change: 1 addition & 0 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ng": "ng",
"start": "ng serve",
"lint": "ng lint",
"lint:fix": "ng lint --fix",
"watch": "ng build --watch --configuration development",
"test": "jest",
"build": "ng build && npm run postbuild",
Expand Down
3 changes: 2 additions & 1 deletion packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"test": "jest --verbose",
"lint": "eslint ./",
"lint:fix": "eslint ./ --fix",
"clean": "shx rm -rf ./dist",
"build:esm": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2015 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2015 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
Expand Down Expand Up @@ -60,4 +61,4 @@
"@types/supertest": "^6.0.0",
"supertest": "^7.0.0"
}
}
}
5 changes: 3 additions & 2 deletions packages/nest/src/context-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EvaluationContext } from '@openfeature/core';
import { ExecutionContext, Inject } from '@nestjs/common';
import type { EvaluationContext } from '@openfeature/core';
import type { ExecutionContext} from '@nestjs/common';
import { Inject } from '@nestjs/common';

/**
* A factory function for creating an OpenFeature {@link EvaluationContext} from Nest {@link ExecutionContext}.
Expand Down
6 changes: 4 additions & 2 deletions packages/nest/src/evaluation-context-interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CallHandler, ExecutionContext, Inject, Injectable, NestInterceptor } from '@nestjs/common';
import { ContextFactory, ContextFactoryToken } from './context-factory';
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import type { ContextFactory} from './context-factory';
import { ContextFactoryToken } from './context-factory';
import { Observable } from 'rxjs';
import { OpenFeature } from '@openfeature/server-sdk';
import { OpenFeatureModule } from './open-feature.module';
Expand Down
8 changes: 5 additions & 3 deletions packages/nest/src/feature.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createParamDecorator, Inject } from '@nestjs/common';
import {
import type {
EvaluationContext,
EvaluationDetails,
FlagValue,
JsonValue,
JsonValue} from '@openfeature/server-sdk';
import {
OpenFeature,
Client,
} from '@openfeature/server-sdk';
import { getOpenFeatureClientToken } from './open-feature.module';
import { from, Observable } from 'rxjs';
import type { Observable } from 'rxjs';
import { from } from 'rxjs';

/**
* Options for injecting an OpenFeature client into a constructor.
Expand Down
17 changes: 10 additions & 7 deletions packages/nest/src/open-feature.module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import {
import type {
DynamicModule,
Module,
FactoryProvider as NestFactoryProvider,
ValueProvider,
ClassProvider,
Provider as NestProvider,
Provider as NestProvider} from '@nestjs/common';
import {
Module,
ExecutionContext,
} from '@nestjs/common';
import {
import type {
Client,
Hook,
OpenFeature,
Provider,
EvaluationContext,
ServerProviderEvents,
EventHandler,
Logger,
Logger} from '@openfeature/server-sdk';
import {
OpenFeature,
AsyncLocalStorageTransactionContextPropagator,
} from '@openfeature/server-sdk';
import { ContextFactory, ContextFactoryToken } from './context-factory';
import type { ContextFactory} from './context-factory';
import { ContextFactoryToken } from './context-factory';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { EvaluationContextInterceptor } from './evaluation-context-interceptor';
import { ShutdownService } from './shutdown.service';
Expand Down
3 changes: 2 additions & 1 deletion packages/nest/src/shutdown.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import type { OnApplicationShutdown } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { OpenFeature } from '@openfeature/server-sdk';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion packages/nest/test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InMemoryProvider } from '@openfeature/server-sdk';
import { ExecutionContext } from '@nestjs/common';
import type { ExecutionContext } from '@nestjs/common';
import { OpenFeatureModule } from '../src';

export const defaultProvider = new InMemoryProvider({
Expand Down
5 changes: 3 additions & 2 deletions packages/nest/test/open-feature-sdk.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import type { INestApplication } from '@nestjs/common';
import supertest from 'supertest';
import { OpenFeatureController, OpenFeatureControllerContextScopedController, OpenFeatureTestService } from './test-app';
import { exampleContextFactory, getOpenFeatureDefaultTestModule } from './fixtures';
Expand Down
6 changes: 4 additions & 2 deletions packages/nest/test/open-feature.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { getOpenFeatureClientToken, OpenFeatureModule, ServerProviderEvents } from '../src';
import { Client, OpenFeature } from '@openfeature/server-sdk';
import type { Client} from '@openfeature/server-sdk';
import { OpenFeature } from '@openfeature/server-sdk';
import { getOpenFeatureDefaultTestModule } from './fixtures';

describe('OpenFeatureModule', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/nest/test/test-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Controller, Get, Injectable, UseInterceptors } from '@nestjs/common';
import { Observable, map } from 'rxjs';
import type { Observable} from 'rxjs';
import { map } from 'rxjs';
import { BooleanFeatureFlag, ObjectFeatureFlag, NumberFeatureFlag, OpenFeatureClient, StringFeatureFlag } from '../src';
import { Client, EvaluationDetails, FlagValue } from '@openfeature/server-sdk';
import type { Client, EvaluationDetails, FlagValue } from '@openfeature/server-sdk';
import { EvaluationContextInterceptor } from '../src';

@Injectable()
Expand Down
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"test": "jest --verbose",
"lint": "eslint ./",
"lint:fix": "eslint ./ --fix",
"clean": "shx rm -rf ./dist",
"build:react-esm": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
"build:react-cjs": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
Expand Down Expand Up @@ -53,4 +54,4 @@
"@openfeature/core": "*",
"@openfeature/web-sdk": "*"
}
}
}
2 changes: 1 addition & 1 deletion packages/react/src/common/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlagEvaluationOptions } from '@openfeature/web-sdk';
import type { FlagEvaluationOptions } from '@openfeature/web-sdk';

export type ReactFlagEvaluationOptions = ({
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/common/suspense.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client, ProviderEvents } from '@openfeature/web-sdk';
import type { Client} from '@openfeature/web-sdk';
import { ProviderEvents } from '@openfeature/web-sdk';

/**
* Suspends until the client is ready to evaluate feature flags.
Expand Down
7 changes: 4 additions & 3 deletions packages/react/src/evaluation/hook-flag-query.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
import type {
EvaluationDetails,
FlagValue,
FlagValue} from '@openfeature/web-sdk';
import {
StandardResolutionReasons
} from '@openfeature/web-sdk';
import { FlagQuery } from '../query';
import type { FlagQuery } from '../query';


// FlagQuery implementation, do not export
Expand Down
10 changes: 6 additions & 4 deletions packages/react/src/evaluation/use-feature-flag.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import {
import type {
Client,
ClientProviderEvents,
EvaluationDetails,
EventHandler,
FlagEvaluationOptions,
FlagValue,
JsonValue,
JsonValue} from '@openfeature/web-sdk';
import {
ProviderEvents,
ProviderStatus,
} from '@openfeature/web-sdk';
import { useEffect, useRef, useState } from 'react';
import { DEFAULT_OPTIONS, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';
import type { ReactFlagEvaluationOptions} from '../common/options';
import { DEFAULT_OPTIONS, normalizeOptions } from '../common/options';
import { suspendUntilReady } from '../common/suspense';
import { useProviderOptions } from '../provider/context';
import { useOpenFeatureClient } from '../provider/use-open-feature-client';
import { useOpenFeatureClientStatus } from '../provider/use-open-feature-client-status';
import { FlagQuery } from '../query';
import type { FlagQuery } from '../query';
import { HookFlagQuery } from './hook-flag-query';
import { isEqual } from '../common/is-equal';

Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/provider/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from '@openfeature/web-sdk';
import type { Client } from '@openfeature/web-sdk';
import React from 'react';
import { NormalizedOptions, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';
import type { NormalizedOptions, ReactFlagEvaluationOptions} from '../common/options';
import { normalizeOptions } from '../common/options';

/**
* The underlying React context.
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/provider/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client, OpenFeature } from '@openfeature/web-sdk';
import type { Client} from '@openfeature/web-sdk';
import { OpenFeature } from '@openfeature/web-sdk';
import * as React from 'react';
import { ReactFlagEvaluationOptions } from '../common/options';
import type { ReactFlagEvaluationOptions } from '../common/options';
import { Context } from './context';

type ClientOrDomain =
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/provider/test-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type {
JsonValue,
Provider} from '@openfeature/web-sdk';
import {
InMemoryProvider,
JsonValue,
NOOP_PROVIDER,
OpenFeature,
Provider,
OpenFeature
} from '@openfeature/web-sdk';
import React from 'react';
import { NormalizedOptions } from '../common/options';
import type { NormalizedOptions } from '../common/options';
import { OpenFeatureProvider } from './provider';

type FlagValueMap = { [flagKey: string]: JsonValue };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { useOpenFeatureClient } from './use-open-feature-client';
import { ProviderEvents, ProviderStatus } from '@openfeature/web-sdk';
import type { ProviderStatus } from '@openfeature/web-sdk';
import { ProviderEvents } from '@openfeature/web-sdk';

/**
* Get the {@link ProviderStatus} for the OpenFeatureClient.
Expand Down
Loading
Loading