Skip to content
Snippets Groups Projects
Verified Commit 6194a77a authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Update ESLint to support new flat config

parent d43b41bb
No related branches found
No related tags found
1 merge request!23Dependencies-related work
node_modules
dist
__tests__
webpack.config.js
.eslintrc.js
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
"import"
],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
env: {
browser: true,
node: false,
commonjs: true,
es6: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: "script",
allowReserved: false,
ecmaFeatures: {
globalReturn: false,
impliedStrict: true,
jsx: false
}
},
rules: {
// Possible problems
"no-constructor-return": 1,
"array-callback-return": 1,
"no-promise-executor-return": 1,
"no-unreachable-loop": 1,
"require-atomic-updates": 1,
"no-duplicate-imports": 2,
"no-template-curly-in-string": 2,
"no-unused-private-class-members": 2,
"@typescript-eslint/no-unused-vars": [ 1, { argsIgnorePattern: "^_", varsIgnorePattern: "^_" } ],
"@typescript-eslint/explicit-member-accessibility": 2,
"@typescript-eslint/explicit-function-return-type": 2,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-inferrable-types": 0,
// Suggestions
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-explicit-any": 0,
"camelcase": 0,
"capitalized-comments": 1,
"dot-notation": 1,
"multiline-comment-style": 1,
"no-bitwise": 1,
"no-div-regex": 1,
"no-else-return": 1,
"no-extend-native": 1,
"no-extra-label": 1,
"no-floating-decimal": 1,
"no-label-var": 1,
"no-labels": 1,
"no-lone-blocks": 1,
"no-lonely-if": 1,
"no-new": 1,
"no-negated-condition": 1,
"no-shadow": 0,
"@typescript-eslint/no-extra-semi": 0,
"@typescript-eslint/no-empty-function": 0,
"prefer-destructuring": 1,
"prefer-template": 1,
"curly": [ 1, "multi" ],
"default-case": [ 1, { commentPattern: "^[sS]kip\\sdefault" } ],
"@typescript-eslint/no-shadow": 2,
"consistent-return": 0,
"consistent-this": 2,
"eqeqeq": 2,
"func-name-matching": 2,
"func-names": 2,
"grouped-accessor-pairs": 2,
"init-declarations": 0,
"no-array-constructor": 2,
"no-caller": 2,
"no-console": 1,
"no-eval": 2,
"no-implied-eval": 2,
"no-extra-bind": 2,
"no-implicit-globals": 2,
"no-mixed-operators": 2,
"no-multi-str": 2,
"no-new-wrappers": 2,
"no-new-object": 2,
"no-new-func": 2,
"no-proto": 2,
"no-return-await": 2,
"no-throw-literal": 2,
"no-unneeded-ternary": 2,
"no-unused-expressions": 2,
"no-useless-call": 2,
"no-useless-computed-key": 2,
"no-useless-concat": 2,
"no-useless-rename": 2,
"no-useless-return": 2,
"no-var": 2,
"prefer-const": 2,
"prefer-numeric-literals": 2,
"prefer-object-has-own": 2,
"prefer-object-spread": 2,
"prefer-promise-reject-errors": 2,
"prefer-regex-literals": 2,
"prefer-rest-params": 2,
"prefer-spread": 2,
"require-await": 2,
"symbol-description": 2,
"yoda": 2,
"spaced-comment": [ 2, "always" ],
"operator-assignment": [ 2, "always" ],
"func-style": [ 2, "expression" ],
"no-return-assign": [ 2, "except-parens" ],
"no-sequences": [ 2, "allowInParentheses" ],
"quote-props": [ 2, "consistent-as-needed" ],
"prefer-arrow-callback": [ 2, { allowNamedFunctions: true } ],
"object-shorthand": [ 2, "always", { avoidQuotes: true } ],
"no-restricted-exports": [ 2, { restrictedNamedExports: [ "default" ] } ],
"no-restricted-syntax": [ 2, "WithStatement" ],
"id-length": [ 2, { min: 2, max: 30, exceptionPatterns: [ "[ei-l]" ] } ],
"@typescript-eslint/typedef": [
2,
{
arrayDestructuring: false,
objectDestructuring: false,
arrowParameter: false,
memberVariableDeclaration: true,
parameter: true,
propertyDeclaration: true,
variableDeclaration: false,
variableDeclarationIgnoreFunction: true
}
],
// Layout and formatting
"eol-last": 1,
"no-multiple-empty-lines": 1,
"rest-spread-spacing": 1,
"semi": 1,
"space-before-blocks": 1,
"wrap-regex": 1,
"space-infix-ops": 1,
"space-before-function-paren": [ 1, "never" ],
"array-bracket-spacing": [ 1, "always" ],
"block-spacing": [ 1, "always" ],
"arrow-parens": [ 1, "as-needed" ],
"function-call-argument-newline": [ 1, "consistent" ],
"array-bracket-newline": [ 1, "consistent" ],
"array-element-newline": [ 1, "consistent" ],
"max-len": [ 1, { code: 160 } ],
"arrow-spacing": [ 1, { before: true, after: true } ],
"semi-spacing": [ 1, { before: false, after: true } ],
"keyword-spacing": [ 1, { before: true, after: false, overrides: {
import: { after: true },
export: { after: true },
from: { after: true },
const: { after: true },
try: { after: true },
catch: { after: true },
do: { after: true },
async: { after: true },
return: { after: true },
default: { after: true },
finally: { after: true }
} } ],
"computed-property-spacing": [ 1, "never", { enforceForClassMembers: false } ],
"comma-dangle": 2,
"comma-spacing": 2,
"space-unary-ops": 2,
"switch-colon-spacing": 2,
"generator-star-spacing": 2,
"implicit-arrow-linebreak": 2,
"linebreak-style": 2,
"lines-between-class-members": 2,
"new-parens": 2,
"no-tabs": 2,
"no-trailing-spaces": 2,
"no-whitespace-before-property": 2,
"no-empty": [ 2, { allowEmptyCatch: true } ],
"indent": [ 2, 2 ],
"semi-style": [ 2, "last" ],
"comma-style": [ 2, "last" ],
"unicode-bom": [ 2, "never" ],
"operator-linebreak": [ 2, "before" ],
"yield-star-spacing": [ 2, "before" ],
"wrap-iife": [ 2, "inside" ],
"quotes": [ 2, "double" ],
"newline-per-chained-call": [ 2, { ignoreChainWithDepth: 2 } ],
"key-spacing": [ 2, { beforeColon: false, mode: "minimum" } ],
"brace-style": [ 2, "1tbs", { allowSingleLine: true } ],
"padding-line-between-statements": [ 2, { blankLine: "always", prev: "*", next: "return" } ],
"import/no-webpack-loader-syntax": 1,
"import/no-self-import": 2,
"import/no-cycle": 2,
"import/no-useless-path-segments": 2,
"import/no-relative-parent-imports": 1,
"import/no-relative-packages": 1,
"import/export": 2,
"import/no-named-as-default": 1,
"import/no-named-as-default-member": 1,
"import/no-deprecated": 1,
"import/no-extraneous-dependencies": 1,
"import/no-mutable-exports": 2,
"import/no-unused-modules": 1,
"import/unambiguous": 2,
"import/no-commonjs": 1,
"import/no-amd": 1,
"import/no-import-module-exports": 1,
"import/no-unassigned-import": 0,
"import/newline-after-import": 2,
"import/first": 2,
"import/exports-last": 0,
"import/no-duplicates": 2,
"import/no-namespace": 0,
"import/order": [
2,
{
alphabetize: {
order: "asc",
caseInsensitive: true
}
}
]
}
};
......@@ -23,7 +23,7 @@ lint:
stage: .pre
extends: .npm_based_job_base
script:
- npm run lint
- npm run lint-ci
build:
stage: build
......
{
"*.ts": "eslint"
"*.{ts,js}": "eslint --max-warnings 0"
}
......@@ -30,12 +30,13 @@ const envTestFor = <GlobalType extends IWorkerBeeGlobals>(
const runner = async<R, Args extends any[]>(checkEqual: boolean, fn: TWorkerBeeTestCallable<R, Args>, ...args: Args): Promise<R> => {
const webData = await page.evaluate(async({ args, globalFunction, webFn, customConfig }) => {
const webData = await page.evaluate(async({ args: pageArgs, globalFunction: globalFn, webFn }) => {
/* eslint-disable no-eval */
eval(`window.webEvalFn = ${webFn};`);
return (window as Window & typeof globalThis & { webEvalFn: Function }).webEvalFn(await globalThis[globalFunction]("web"), ...args);
}, { args, globalFunction: globalFunction.name, webFn: fn.toString(), customConfig: globalThis.config });
let nodeData = await fn(await (globalFunction as Function)("node"), ...args);
return (window as Window & typeof globalThis & { webEvalFn: (...args: any[]) => any }).webEvalFn(await globalThis[globalFn]("web"), ...pageArgs);
}, { args, globalFunction: globalFunction.name, webFn: fn.toString() });
let nodeData = await fn(await (globalFunction as (...args: any[]) => any)("node"), ...args);
if(typeof nodeData === "object") // Remove prototype data from the node result to match webData
nodeData = JSON.parse(JSON.stringify(nodeData));
......@@ -46,7 +47,7 @@ const envTestFor = <GlobalType extends IWorkerBeeGlobals>(
return webData;
};
const using = function<R, Args extends any[]>(fn: TWorkerBeeTestCallable<R, Args>, ...args: Args) {
const using = function<R, Args extends any[]>(fn: TWorkerBeeTestCallable<R, Args>, ...args: Args): Promise<R> {
return runner.bind(undefined, true)(fn as any, ...args);
};
using.dynamic = runner.bind(undefined, false);
......@@ -55,7 +56,7 @@ const envTestFor = <GlobalType extends IWorkerBeeGlobals>(
};
export const test = base.extend<IWorkerBeeTest>({
workerbeeTest: async({ page }, use) => {
workerbeeTest: ({ page }, use) => {
use(envTestFor(page, createTestFor));
}
});
/* eslint-disable no-console */
import type { ApiAccount } from "@hiveio/wax";
import { expect } from "@playwright/test";
import { ChromiumBrowser, ConsoleMessage, chromium } from "playwright";
import type { IBlockData } from "../../src/interfaces";
import type { IStartConfiguration } from "../../src/bot";
import type { IBlockData } from "../../src/interfaces";
import { test } from "../assets/jest-helper";
......@@ -25,18 +27,20 @@ test.describe("WorkerBee Bot events test", () => {
await page.goto("http://localhost:8080/__tests__/assets/test.html", { waitUntil: "load" });
});
test("Allow to pass explicit chain", async ({ workerbeeTest }) => {
const explicitChainTest = await workerbeeTest(async ({ WorkerBee }) => {
test("Allow to pass explicit chain", async({ workerbeeTest }) => {
const explicitChainTest = await workerbeeTest(async({ WorkerBee }) => {
/// Prepare helper WorkerBee instance just to provide IHiveChainInterface instance.
/// It is a problem in PW tests to reference whole wax, since its dependencies need to be declared at importmap in test.html
/*
* Prepare helper WorkerBee instance just to provide IHiveChainInterface instance.
* It is a problem in PW tests to reference whole wax, since its dependencies need to be declared at importmap in test.html
*/
const customWaxConfig = { apiEndpoint: "https://api.openhive.network", chainId: "badf00d" };
const customConfig: IStartConfiguration = { chainOptions: customWaxConfig };
const chainOwner = new WorkerBee(customConfig);
/// call start just to initialize chain member in WorkerBee object.
// Call start just to initialize chain member in WorkerBee object.
await chainOwner.start();
/// stop does not affect chain property, so we can avoid making ineffective api calls.
// Stop does not affect chain property, so we can avoid making ineffective api calls.
await chainOwner.stop();
const localChain = chainOwner.chain;
......@@ -45,7 +49,7 @@ test.describe("WorkerBee Bot events test", () => {
await bot.start();
/// validate endpoints to easily check that instances match
// Validate endpoints to easily check that instances match
const validChainInstance = bot.chain !== undefined && localChain !== undefined && bot.chain.endpointUrl === localChain.endpointUrl;
await bot.delete();
......@@ -67,7 +71,7 @@ test.describe("WorkerBee Bot events test", () => {
});
test("Should call proper events", async({ workerbeeTest }) => {
const handlersCalled = await workerbeeTest(async({ WorkerBee }) => {
const result = await workerbeeTest(async({ WorkerBee }) => {
const bot = new WorkerBee();
bot.on("error", console.error);
......@@ -82,11 +86,11 @@ test.describe("WorkerBee Bot events test", () => {
return handlersCalled;
});
expect(handlersCalled).toStrictEqual(2);
expect(result).toStrictEqual(2);
});
test("Should be able to parse at least 2 blocks from the remote", async({ workerbeeTest }) => {
const blocksParsed = await workerbeeTest.dynamic(async({ WorkerBee }, HIVE_BLOCK_INTERVAL) => {
const result = await workerbeeTest.dynamic(async({ WorkerBee }, hiveBlockInterval) => {
const bot = new WorkerBee();
bot.on("error", console.error);
......@@ -99,7 +103,7 @@ test.describe("WorkerBee Bot events test", () => {
await bot.start();
await Promise.race([
new Promise(res => { setTimeout(res, HIVE_BLOCK_INTERVAL * 4); }),
new Promise(res => { setTimeout(res, hiveBlockInterval * 4); }),
new Promise<void>(res => {
bot.on("stop", res);
})
......@@ -111,17 +115,18 @@ test.describe("WorkerBee Bot events test", () => {
return blocksParsed;
}, HIVE_BLOCK_INTERVAL);
expect(blocksParsed).toBeGreaterThanOrEqual(1);
expect(result).toBeGreaterThanOrEqual(1);
});
test("Should be able to use async iterator on bot", async({ workerbeeTest }) => {
const blocksParsed = await workerbeeTest.dynamic(async({ WorkerBee }, HIVE_BLOCK_INTERVAL) => {
const result = await workerbeeTest.dynamic(async({ WorkerBee }, hiveBlockInterval) => {
const bot = new WorkerBee();
bot.on("error", console.error);
let blocksParsed = 0;
await Promise.race([
/* eslint-disable-next-line no-async-promise-executor */
new Promise<void>(async res => {
await bot.start();
......@@ -135,7 +140,7 @@ test.describe("WorkerBee Bot events test", () => {
res();
}),
new Promise(res => { setTimeout(res, HIVE_BLOCK_INTERVAL * 4); })
new Promise(res => { setTimeout(res, hiveBlockInterval * 4); })
]);
await bot.stop();
......@@ -144,15 +149,16 @@ test.describe("WorkerBee Bot events test", () => {
return blocksParsed;
}, HIVE_BLOCK_INTERVAL);
expect(blocksParsed).toBeGreaterThanOrEqual(1);
expect(result).toBeGreaterThanOrEqual(1);
});
test("Should be able to use block observer", async({ workerbeeTest }) => {
await workerbeeTest(async({ WorkerBee }, HIVE_BLOCK_INTERVAL) => {
await workerbeeTest(async({ WorkerBee }, hiveBlockInterval) => {
const bot = new WorkerBee();
bot.on("error", console.error);
await Promise.race([
/* eslint-disable-next-line no-async-promise-executor */
new Promise<void>(async res => {
await bot.start();
......@@ -170,7 +176,7 @@ test.describe("WorkerBee Bot events test", () => {
}
});
}),
new Promise(res => { setTimeout(res, HIVE_BLOCK_INTERVAL * 4); })
new Promise(res => { setTimeout(res, hiveBlockInterval * 4); })
]);
await bot.stop();
......@@ -179,11 +185,12 @@ test.describe("WorkerBee Bot events test", () => {
});
test("Should be able to use full manabar regeneration time observer", async({ workerbeeTest }) => {
await workerbeeTest(async({ WorkerBee }, HIVE_BLOCK_INTERVAL) => {
await workerbeeTest(async({ WorkerBee }, hiveBlockInterval) => {
const bot = new WorkerBee();
bot.on("error", console.error);
await Promise.race([
/* eslint-disable-next-line no-async-promise-executor */
new Promise<void>(async res => {
await bot.start();
......@@ -191,14 +198,14 @@ test.describe("WorkerBee Bot events test", () => {
const observer = bot.observe.accountFullManabar("initminer");
observer.subscribe({
next(acc) {
next(acc: ApiAccount) {
console.info(`Account has full manabar: ${acc.voting_manabar.current_mana}`);
res();
}
});
}),
new Promise(res => { setTimeout(res, HIVE_BLOCK_INTERVAL * 4); })
new Promise(res => { setTimeout(res, hiveBlockInterval * 4); })
]);
await bot.stop();
......
import path from "node:path";
import { fileURLToPath } from "node:url";
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import _import from "eslint-plugin-import";
import globals from "globals";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [ {
ignores: [
"**/node_modules",
"**/dist",
"examples"
]
}, ...compat.extends("eslint:recommended"), {
plugins: {
import: fixupPluginRules(_import)
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2020
},
ecmaVersion: 11,
sourceType: "module",
},
rules: {
"require-atomic-updates": 1,
"no-unused-private-class-members": 1,
"capitalized-comments": 1,
"multiline-comment-style": 1,
"no-else-return": 1,
"curly": [ 1, "multi" ],
"default-case": [ 1, {
commentPattern: "^[sS]kip\\sdefault"
} ],
"consistent-return": 0,
"consistent-this": 2,
"no-console": 1,
"no-eval": 2,
"no-extra-bind": 2,
"no-useless-return": 2,
"no-var": 2,
"prefer-const": 2,
"prefer-object-spread": 2,
"prefer-spread": 2,
"require-await": 2,
"func-style": [ 2, "expression" ],
"quote-props": [ 2, "consistent-as-needed" ],
"no-restricted-syntax": [ 2, "WithStatement" ],
"id-length": [ 2, {
min: 2,
max: 30,
exceptionPatterns: [ "[ei-l]" ]
} ],
"eol-last": 1,
"no-multiple-empty-lines": 1,
"max-len": [ 1, {
code: 160
} ],
"comma-spacing": 2,
"linebreak-style": 2,
"no-tabs": 2,
"no-trailing-spaces": 2,
"indent": [ 2, 2 ],
"semi-style": [ 2, "last" ],
"comma-style": [ 2, "last" ],
"quotes": [ 2, "double" ],
"brace-style": [ 2, "1tbs", {
allowSingleLine: true
} ],
"import/no-self-import": 2,
"import/no-cycle": 2,
"import/export": 2,
"import/no-unused-modules": 1,
"import/no-commonjs": 1,
"import/newline-after-import": 2,
"import/first": 2,
"import/no-duplicates": 2,
"import/order": [ 2, {
alphabetize: {
order: "asc",
caseInsensitive: true
}
} ],
// Those will be handled later in the TypeScript section
"no-redeclare": 0,
"no-undef": 0
}
}, {
files: [ "**/*.ts" ],
plugins: {
"@typescript-eslint": typescriptEslint
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.es2020
},
parser: tsParser,
ecmaVersion: 11,
sourceType: "module"
},
rules: {
...typescriptEslint.configs.recommended.rules,
"@typescript-eslint/no-unused-vars": [ 1, {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_"
} ],
"@typescript-eslint/explicit-member-accessibility": 2,
"@typescript-eslint/explicit-function-return-type": 2,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/typedef": [ 2, {
arrayDestructuring: false,
objectDestructuring: false,
arrowParameter: false,
memberVariableDeclaration: true,
parameter: true,
propertyDeclaration: true,
variableDeclaration: false,
variableDeclarationIgnoreFunction: true
} ],
"@typescript-eslint/no-extra-semi": 0,
"@typescript-eslint/no-empty-function": 0
}
} ];
......@@ -20,7 +20,8 @@
"license": "SEE LICENSE IN LICENSE.md",
"private": false,
"scripts": {
"lint": "eslint src --ext .js,.ts --max-warnings=0 --ignore-pattern *.d.ts --fix",
"lint": "npm run lint-ci -- --fix",
"lint-ci": "eslint --max-warnings=0",
"postinstall": "ls-engines && husky",
"build": "tsc",
"postbuild": "rollup -c",
......@@ -35,17 +36,21 @@
"dist/bundle/index.js"
],
"devDependencies": {
"@eslint/compat": "^1.2.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@playwright/test": "^1.39.0",
"@rollup/plugin-commonjs": "^27.0.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@types/events": "^3.0.3",
"@types/node": "^18.19.50",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"buffer": "^5.5.0||^6.0.0",
"dotenv": "^16.3.1",
"eslint": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint": "^9.14.0",
"eslint-plugin-import": "^2.31.0",
"globals": "^15.12.0",
"http-server": "^14.1.1",
"husky": "^9.1.5",
"lint-staged": "^15.2.2",
......@@ -73,6 +78,12 @@
"engines": {
"node": ">= 18"
},
"devEngines": {
"runtime": {
"name": "node",
"version": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"publishConfig": {
"registry": "https://RegistryPlaceholder",
"tag": "DistTagPlaceholder"
......
// This is a workaround for https://github.com/microsoft/playwright/issues/18282#issuecomment-1612266345
import { defineConfig } from '@playwright/test';
import { defineConfig } from "@playwright/test";
export default defineConfig({
reporter: [
['junit', { outputFile: 'results.xml' }],
['json', { outputFile: 'results.json' }]
[ "junit", { outputFile: "results.xml" } ],
[ "json", { outputFile: "results.json" } ]
],
projects: [
{
......@@ -14,6 +14,6 @@ export default defineConfig({
],
// Run your local dev server before starting the tests
webServer: {
command: 'npx http-server'
command: "npx http-server"
}
});
This diff is collapsed.
import dts from 'rollup-plugin-dts';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import dts from "rollup-plugin-dts";
const commonConfiguration = (packEntire = false) => ([
{
input: `dist/index.js`,
input: "dist/index.js",
output: {
format: 'es',
name: 'workerbee',
file: `dist/bundle/${packEntire ? 'web-full' : 'index'}.js`
format: "es",
name: "workerbee",
file: `dist/bundle/${packEntire ? "web-full" : "index"}.js`
},
plugins: [
nodeResolve({
......@@ -19,9 +20,9 @@ const commonConfiguration = (packEntire = false) => ([
commonjs()
]
}, {
input: `dist/index.d.ts`,
input: "dist/index.d.ts",
output: [
{ file: `dist/bundle/${packEntire ? 'web-full' : 'index'}.d.ts`, format: "es" }
{ file: `dist/bundle/${packEntire ? "web-full" : "index"}.d.ts`, format: "es" }
],
plugins: [
dts()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment