diff --git a/.dist.eslintrc b/.dist.eslintrc index fc08714e8..2d25a42c2 100644 --- a/.dist.eslintrc +++ b/.dist.eslintrc @@ -1,5 +1,5 @@ { - "extends": ["eslint:recommended"], + "extends": ["eslint:recommended", "plugin:compat/recommended"], "env": { "node": false, "browser": true, @@ -8,6 +8,14 @@ }, "plugins": ["compat"], "rules": { + "node/no-unsupported-features/es-builtins": ["error", { + "version": ">=8.0.0", + "ignores": [ + "Atomics", + "BigInt", + "SharedArrayBuffer" + ] + }], "compat/compat": "error", "no-console": "off", "no-empty": "off", @@ -44,7 +52,9 @@ "Reflect", "WeakMap", "WeakRef", - "WeakSet" + "WeakSet", + "Atomics", + "SharedArrayBuffer" ] } } diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..c97b150b5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,38 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:node/recommended" + ], + "env": { + "node": true, + "browser": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 2021 + }, + "overrides": [ + { + "files": "test/**/*.js", + "env": { + "mocha": true + }, + "rules": { + "no-prototype-builtins": "off", + "node/no-deprecated-api": "warn", + "node/no-extraneous-require": "warn", + "no-unused-vars": "warn" + } + } + ], + "rules": { + "node/no-unsupported-features/node-builtins": "off", + "node/no-unsupported-features/es-syntax": "off", + "node/no-exports-assign": "off" + }, + "globals": { + "ActiveXObject": "readonly" + } + + +} \ No newline at end of file diff --git a/.lib.eslintrc b/.lib.eslintrc index 8f3fbf44c..318fa0b59 100644 --- a/.lib.eslintrc +++ b/.lib.eslintrc @@ -8,7 +8,6 @@ "no-console": "off", "no-unused-vars": "off", "no-empty": "off", - "node/no-unsupported-features/node-builtins": "off", "no-func-assign": "off", "no-global-assign": ["error", {"exceptions": ["exports"]}], "no-fallthrough": "off", @@ -22,6 +21,13 @@ "globals": { "ActiveXObject": "readable" } + }, + { + "files": [ "lib/node/http2wrapper.js" ], + "rules": { + "node/no-unsupported-features/es-builtins": "off", + "node/no-unsupported-features/node-builtins": "off" + } } ] } diff --git a/package.json b/package.json index 558551bba..799e7990d 100644 --- a/package.json +++ b/package.json @@ -155,7 +155,7 @@ "build:dist": "npm run browserify && npm run minify", "build:lib": "babel --config-file ./.lib.babelrc src --out-dir lib", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", - "lint": "xo && remark . -qfo && eslint -c .lib.eslintrc lib && eslint -c .dist.eslintrc dist", + "lint": "eslint -c .eslintrc src test && remark . -qfo && eslint -c .lib.eslintrc lib/**/*.js && eslint -c .dist.eslintrc dist/**/*.js", "minify": "cross-env NODE_ENV=production browserify src/node/index.js -o dist/superagent.min.js -s superagent -g [ babelify --configFile ./.dist.babelrc ] -p tinyify", "nyc": "cross-env NODE_ENV=test nyc ava", "test": "npm run build && npm run lint && make test", @@ -165,6 +165,7 @@ "xo": { "prettier": true, "space": true, + "nodeVersion": false, "extends": [ "xo-lass" ], diff --git a/src/client.js b/src/client.js index f9a9dfed5..444fe1e48 100644 --- a/src/client.js +++ b/src/client.js @@ -71,19 +71,19 @@ request.getXHR = () => { try { return new ActiveXObject('Microsoft.XMLHTTP'); - } catch {} + } catch {/**/} try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); - } catch {} + } catch {/**/} try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); - } catch {} + } catch {/**/} try { return new ActiveXObject('Msxml2.XMLHTTP'); - } catch {} + } catch {/**/} throw new Error('Browser-only version of superagent could not find XHR'); }; diff --git a/test/client/request.js b/test/client/request.js index cc129f183..3263bddb7 100644 --- a/test/client/request.js +++ b/test/client/request.js @@ -55,7 +55,6 @@ describe('request', function () { try { var file = new File([''], 'image.jpg', { type: 'image/jpeg' }); - // eslint-disable-next-line unicorn/prefer-optional-catch-binding } catch (err) { // Skip if file constructor not supported. return next(); diff --git a/test/node/toError.js b/test/node/toError.js index fb1a5ce50..80c9abaf6 100644 --- a/test/node/toError.js +++ b/test/node/toError.js @@ -26,7 +26,7 @@ before(function listen(done) { describe('res.toError()', () => { it('should return an Error', (done) => { - request.get(base).end((error, res) => { + request.get(base).end((err, res) => { var error = res.toError(); assert.equal(error.status, 400); assert.equal(error.method, 'GET');