Skip to content

Commit

Permalink
Remove promise.withresolvers; eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
KODerFunk committed Dec 10, 2023
1 parent 30afd70 commit 072a9c2
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 104 deletions.
53 changes: 53 additions & 0 deletions .eslint-configs/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"extends": [
"eslint:all"
],
"rules": {
"array-element-newline": ["error", "consistent"],
"capitalized-comments": "off",
"class-methods-use-this": "off",
"comma-dangle": ["error", "always-multiline"],
"consistent-return": "off",
"curly": ["error", "multi-line"],
"default-case": "off",
"dot-location": ["error", "property"],
"eol-last": "error",
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"function-call-argument-newline": ["error", "consistent"],
"function-paren-newline": ["error", "multiline-arguments"],
"id-length": ["error", { "exceptions": ["q", "x", "y"] }],
"indent": ["error", 2, { "SwitchCase": 1 }],
"line-comment-position": "off",
"multiline-comment-style": "off",
"multiline-ternary": "off",
"no-console": "error",
"no-duplicate-imports": "off",
"no-inline-comments": "off",
"no-mixed-operators": "off",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0, "maxBOF": 0 }],
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-ternary": "off",
"no-trailing-spaces": "error",
"no-undefined": "off",
"no-use-before-define": ["error", { "functions": false }],
"no-void": "off",
"no-warning-comments": "off",
"object-curly-spacing": ["error", "always"],
"object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true }],
"one-var": ["error", "never"],
"operator-linebreak": ["error", "before", {
"overrides": {
"=": "after"
}
}],
"padded-blocks": ["error", "never"],
"quote-props": ["error", "consistent-as-needed"],
"quotes": ["error", "single"],
"require-unicode-regexp": "off",
"semi": ["error", "never"],
"sort-imports": "off",
"sort-keys": "off",
"spaced-comment": "off"
}
}
102 changes: 102 additions & 0 deletions .eslint-configs/typescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"extends": [
"plugin:@typescript-eslint/all"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/ban-types": ["error", {
"types": {
"{}": false
}
}],
"@typescript-eslint/comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/comma-spacing": "error",
"@typescript-eslint/consistent-type-imports": ["error", {
"prefer": "type-imports",
"disallowTypeAnnotations": false
}],
"@typescript-eslint/explicit-member-accessibility": ["error", { "accessibility": "no-public" }],
"@typescript-eslint/indent": ["error", 2, {
"SwitchCase": 1,
"ignoredNodes": [
"FunctionExpression > .params[decorators.length > 0]",
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
"ClassBody.body > PropertyDefinition[decorators.length > 0] > .key",
"TSTypeParameterInstantiation",
"TSIntersectionType"
]
}],
"@typescript-eslint/init-declarations": "off",
"@typescript-eslint/lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"max-params": "off",
"@typescript-eslint/max-params": ["error", { "max": 5 }],
"@typescript-eslint/member-delimiter-style": ["error", {
"multiline": {
"delimiter": "none",
"requireLast": true
},
"singleline": {
"delimiter": "comma",
"requireLast": false
},
"multilineDetection": "brackets"
}],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksConditionals": true,
"checksVoidReturn": {
"arguments": true,
"attributes": false,
"properties": true,
"returns": true,
"variables": true
}
}
],
"@typescript-eslint/no-type-alias": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}],
"@typescript-eslint/no-use-before-define": ["error", {
"functions": false,
"classes": true,
"variables": true,
"enums": true,
"typedefs": true,
"ignoreTypeReferences": true
}],
"@typescript-eslint/object-curly-spacing": ["error", "always"],
"@typescript-eslint/parameter-properties": ["error", { "prefer": "parameter-property" }],
"prefer-destructuring": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/quotes": ["error", "single"],
"@typescript-eslint/no-extra-parens": "off",
"@typescript-eslint/no-magic-numbers": ["error", {
"ignore": [
0
],
"ignoreArrayIndexes": true,
"detectObjects": false
}],
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/sort-type-constituents": "off",
"@typescript-eslint/sort-type-union-intersection-members": "off",
"@typescript-eslint/space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
"@typescript-eslint/strict-boolean-expressions": "off"
}
}
50 changes: 50 additions & 0 deletions .eslint-configs/unicorn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"extends": [
"plugin:unicorn/all"
],
"rules": {
"unicorn/filename-case": ["error", {
"cases": {
"camelCase": true,
"pascalCase": true
},
"ignore": [
"\\.d\\.ts$"
]
}],
"unicorn/no-array-callback-reference": "off",
"unicorn/no-keyword-prefix": "off",
"unicorn/no-nested-ternary": "off",
"unicorn/no-null": "off",
"unicorn/no-useless-undefined": "off",
"unicorn/numeric-separators-style": ["error", {
"number": {
"minimumDigits": 4
}
}],
"unicorn/prefer-top-level-await": "off",
"unicorn/prevent-abbreviations": ["error", {
"replacements": {
"args": false,
"db": false,
"dev": false,
"dist": false,
"e": false,
"env": false,
"err": false,
"fn": false,
"func": false,
"params": false,
"prev": false,
"prop": false,
"props": false,
"ref": false,
"req": false,
"res": false
},
"ignore": [
"prevState"
]
}]
}
}
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"root": true,
"extends": [
"./.eslint-configs/base.json",
"./.eslint-configs/unicorn.json"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx"
],
"extends": [
"./.eslint-configs/typescript.json"
]
},
{
"files": [
"dist/*.js"
],
"rules": {
"init-declarations": "off",
"no-magic-numbers": "off",
"no-undef": "off",
"no-unused-vars": "off"
}
}
]
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"files": [
"dist",
"src",
"typings",
"package.json",
"README.md",
"LICENSE"
Expand All @@ -25,23 +24,24 @@
},
"scripts": {
"ts-check": "tsc --noEmit --incremental",
"lint": "eslint src --fix",
"lint:ci": "eslint src",
"test": "jest",
"test:ci": "jest --ci",
"precommit": "npm run lint && npm run ts-check && npm run lint",
"prebuild": "rm -rf ./dist",
"build": "tsc --project tsconfig.build.json",
"postbuild": "eslint dist --fix",
"prerelease": "npm run build",
"release": "np"
},
"dependencies": {
"promise.withresolvers": "^1.0.1"
},

"devDependencies": {
"@total-typescript/ts-reset": "^0.5.1",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"eslint": "^8.55.0",
"eslint-plugin-react-perf": "^3.3.1",
"eslint-plugin-unicorn": "^49.0.0",
"jest": "^29.7.0",
"np": "^9.2.0",
Expand Down
23 changes: 12 additions & 11 deletions src/BatchLoader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { IBatchLoaderItem, IBatchLoaderOptions } from './BatchLoader.types'
/* eslint-disable max-lines, max-lines-per-function, max-statements, @typescript-eslint/no-magic-numbers */
import type { BatchLoaderStatus, IBatchLoaderItem, IBatchLoaderOptions } from './BatchLoader.types'
import BatchLoader from './BatchLoader'
import ImmutableBatchLoaderItemsStore from './ImmutableBatchLoaderItemsStore'

const TEST_TIMEOUT = 1

function timeout(delay = 0) {
function timeout(delay = 0): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, delay)
})
Expand All @@ -20,7 +21,7 @@ describe('BatchLoader', () => {
resolve(
ids.map((id) => ({
test: `test_${id}_${salt}`,
}))
})),
)
}, TEST_TIMEOUT)
}),
Expand Down Expand Up @@ -114,7 +115,7 @@ describe('BatchLoader', () => {
() => state,
(newState) => {
state = newState
}
},
)

const itemsStoreSpies = {
Expand All @@ -131,7 +132,7 @@ describe('BatchLoader', () => {
resolve(
ids.map((id) => ({
test: `test_${id}_${salt}`,
}))
})),
)
}, TEST_TIMEOUT)
}),
Expand Down Expand Up @@ -230,7 +231,7 @@ describe('BatchLoader', () => {
])
})

it("should work with default refetchStrategy ('unfetched')", async () => {
it('should work with default refetchStrategy (\'unfetched\')', async () => {
let salt = '1'

const options: IBatchLoaderOptions<string, { test: string }> = {
Expand All @@ -239,14 +240,14 @@ describe('BatchLoader', () => {
resolve(
ids.map((id) => ({
test: `test_${id}_${salt}`,
}))
})),
)
}, TEST_TIMEOUT)
}),
}

const batchFetchSpy = jest.spyOn(options, 'batchFetch')
const testBatchLoader = new BatchLoader<string, { test: string }>(options)
const testBatchLoader = new BatchLoader<string, { test: string }>(options) as BatchLoader<string, { test: string }> & { batchStatus: BatchLoaderStatus }

expect(testBatchLoader.batchStatus).toStrictEqual('unrequested')
expect(testBatchLoader.getState('a')).toStrictEqual({
Expand Down Expand Up @@ -325,7 +326,7 @@ describe('BatchLoader', () => {
expect(batchFetchSpy).toHaveBeenNthCalledWith(2, ['c'])
})

it("should work with refetchStrategy: 'refresh'", async () => {
it('should work with refetchStrategy: \'refresh\'', async () => {
let salt = '1'

const options: IBatchLoaderOptions<string, { test: string }> = {
Expand All @@ -334,15 +335,15 @@ describe('BatchLoader', () => {
resolve(
ids.map((id) => ({
test: `test_${id}_${salt}`,
}))
})),
)
}, TEST_TIMEOUT)
}),
refetchStrategy: 'refresh',
}

const batchFetchSpy = jest.spyOn(options, 'batchFetch')
const testBatchLoader = new BatchLoader<string, { test: string }>(options)
const testBatchLoader = new BatchLoader<string, { test: string }>(options) as BatchLoader<string, { test: string }> & { batchStatus: BatchLoaderStatus }

expect(testBatchLoader.batchStatus).toStrictEqual('unrequested')
expect(testBatchLoader.getState('a')).toStrictEqual({
Expand Down
Loading

0 comments on commit 072a9c2

Please sign in to comment.