diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 145ce4ae..00000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,37 +0,0 @@ -extends: "eslint:recommended" -parserOptions: - ecmaVersion: 2020 - sourceType: "module" -env: - node: true - es6: true - mocha: true -rules: - consistent-return: "error" - curly: "error" - default-case: "error" - dot-notation: "error" - eqeqeq: "error" - no-extend-native: "error" - no-implicit-coercion: "error" - no-loop-func: "error" - no-multi-spaces: "error" - no-throw-literal: "error" - global-require: "error" - no-path-concat: "error" - brace-style: ["error", "1tbs", {allowSingleLine: true}] - camelcase: "error" - consistent-this: ["error", "self"] - indent: ["error", "tab", {SwitchCase: 1}] - linebreak-style: ["error", "unix"] - eol-last: "error" - quotes: ["error", "single"] - semi: "error" - space-infix-ops: "error" - space-unary-ops: "error" - func-names: "warn" - space-before-function-paren: "warn" - no-spaced-func: "warn" - keyword-spacing: "error" - space-before-blocks: "error" - no-console: "error" diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..fbd8b306 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,50 @@ +import js from '@eslint/js'; +import stylistic from '@stylistic/eslint-plugin'; +import globals from 'globals'; + +export default [ + js.configs.recommended, + { + files: ['lib/**/*.js', 'index.mjs'], + plugins: { + '@stylistic': stylistic + }, + languageOptions: { + ecmaVersion: 2020, + sourceType: 'module', + globals: { + ...globals.node, + ...globals.mocha + } + }, + rules: { + 'consistent-return': 'error', + 'curly': 'error', + 'default-case': 'error', + 'dot-notation': 'error', + 'eqeqeq': 'error', + 'no-extend-native': 'error', + 'no-implicit-coercion': 'error', + 'no-loop-func': 'error', + 'no-throw-literal': 'error', + 'camelcase': 'error', + 'consistent-this': ['error', 'self'], + 'func-names': 'warn', + 'no-console': 'error', + + '@stylistic/no-multi-spaces': 'error', + '@stylistic/brace-style': ['error', '1tbs', {allowSingleLine: true}], + '@stylistic/indent': ['error', 'tab', {SwitchCase: 1}], + '@stylistic/linebreak-style': ['error', 'unix'], + '@stylistic/eol-last': 'error', + '@stylistic/quotes': ['error', 'single'], + '@stylistic/semi': 'error', + '@stylistic/space-infix-ops': 'error', + '@stylistic/space-unary-ops': 'error', + '@stylistic/space-before-function-paren': 'warn', + '@stylistic/function-call-spacing': ['warn', 'never'], + '@stylistic/keyword-spacing': 'error', + '@stylistic/space-before-blocks': 'error' + } + } +]; diff --git a/lib/resource.js b/lib/resource.js index c57ebf1d..cb94435f 100644 --- a/lib/resource.js +++ b/lib/resource.js @@ -17,10 +17,9 @@ class Resource { createChild (url, filename) { const child = new Resource(url, filename); - let currentDepth = this.getDepth(); child.parent = this; - child.depth = ++currentDepth; + child.depth = this.getDepth() + 1; this.children.push(child); diff --git a/lib/utils/index.js b/lib/utils/index.js index cecf63b4..e59daefb 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -49,7 +49,7 @@ function getPathnameFromUrl (u) { const pathname = url.parse(u).pathname; try { return decodeURI(pathname); - } catch (e) { + } catch { return pathname; } } @@ -110,7 +110,7 @@ function sanitizeFilename (filename) { function normalizeUrl (u, opts) { try { return normalize(u, extend({removeTrailingSlash: false, stripHash: true}, opts)); - } catch (e) { + } catch { return u; } } diff --git a/package.json b/package.json index 753f4923..0392245a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "scripts": { "test": "c8 --all --reporter=text --reporter=lcov mocha --recursive --timeout 7000 ./test/unit/ ./test/functional", "test-e2e": "mocha --timeout 300000 ./test/e2e/*-test.js", - "eslint": "eslint lib/** index.mjs" + "eslint": "eslint lib index.mjs" }, "repository": { "type": "git", @@ -48,9 +48,12 @@ "srcset": "^5.0.0" }, "devDependencies": { + "@eslint/js": "^10.0.1", + "@stylistic/eslint-plugin": "^5.10.0", "c8": "^11.0.0", "chai": "^6.2.0", - "eslint": "^8.5.0", + "eslint": "^10.5.0", + "globals": "^17.7.0", "mocha": "^11.0.1", "nock": "^14.0.0", "sinon": "^21.0.0"