diff --git a/.eslintrc b/.eslintrc index a382dbe4d..e4ea18a0a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,14 +16,14 @@ ], "globals": { "Promise": true }, "rules": { - "strict": 0, - "camelcase": [2, {"properties": "never"}], - "quotes": [2, "single", "avoid-escape"], - "no-underscore-dangle": 0, - "no-useless-escape": 0, - "complexity": [2, { "max": 35 }], - "no-use-before-define": [0, { "functions": false }], - "no-unused-vars": [2, { "argsIgnorePattern": "^_" }], - "no-prototype-builtins": 0 + "strict": "off", + "camelcase": ["error", {"properties": "never"}], + "quotes": ["error", "single", "avoid-escape"], + "no-underscore-dangle": "off", + "no-useless-escape": "off", + "complexity": ["error", {"max": 32}], + "no-use-before-define": ["error", { "functions": false }], + "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], + "no-prototype-builtins": "off" } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5711a1f12..3ae8ed604 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: matrix: node-version: [8, 10, 12] + name: Test / Node ${{ matrix.node-version }} steps: - uses: actions/checkout@v2 with: @@ -27,5 +28,8 @@ jobs: - name: npm install run: npm install + - name: Lint + run: npm run lint + - name: Run tests run: npm run test_ci diff --git a/Makefile b/Makefile index 950407791..ef5c3aca4 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,8 @@ TESTS = test/index.html REPORTER = dot -build: - @npm run build +build lint test test-browser test-server test_ci: + @npm run $@ @echo "" -test: - @npm run test - @echo "" - -test-browser: - @npm run test-browser - @echo "" - -test-server: - @npm run test-server - @echo "" - -test_ci: - @npm run test_ci - @echo "" - -.PHONY: test test_ci +.PHONY: build lint test test-browser test-server test_ci diff --git a/src/browser/core.js b/src/browser/core.js index a4e0abaf6..1a928ce56 100644 --- a/src/browser/core.js +++ b/src/browser/core.js @@ -13,6 +13,27 @@ var predicates = require('./predicates'); var sharedPredicates = require('../predicates'); var errorParser = require('../errorParser'); +var defaults = require('../defaults'); +var scrubFields = require('./defaults/scrubFields'); + +var defaultOptions = { + version: defaults.version, + scrubFields: scrubFields.scrubFields, + logLevel: defaults.logLevel, + reportLevel: defaults.reportLevel, + uncaughtErrorLevel: defaults.uncaughtErrorLevel, + endpoint: defaults.endpoint, + verbose: false, + enabled: true, + transmit: true, + sendConfig: false, + includeItemsInTelemetry: true, + captureIp: true, + inspectAnonymousErrors: true, + ignoreDuplicateErrors: true, + wrapGlobalEventHandlers: false +}; + function Rollbar(options, client) { this.options = _.handleOptions(defaultOptions, options, null, logger); this.options._configuredOptions = options; @@ -537,25 +558,4 @@ function _gWindow() { return ((typeof window != 'undefined') && window) || ((typeof self != 'undefined') && self); } -var defaults = require('../defaults'); -var scrubFields = require('./defaults/scrubFields'); - -var defaultOptions = { - version: defaults.version, - scrubFields: scrubFields.scrubFields, - logLevel: defaults.logLevel, - reportLevel: defaults.reportLevel, - uncaughtErrorLevel: defaults.uncaughtErrorLevel, - endpoint: defaults.endpoint, - verbose: false, - enabled: true, - transmit: true, - sendConfig: false, - includeItemsInTelemetry: true, - captureIp: true, - inspectAnonymousErrors: true, - ignoreDuplicateErrors: true, - wrapGlobalEventHandlers: false -}; - module.exports = Rollbar; diff --git a/src/browser/shim.js b/src/browser/shim.js index abebaaeb0..d33a2d187 100644 --- a/src/browser/shim.js +++ b/src/browser/shim.js @@ -7,9 +7,8 @@ function _wrapInternalErr(f) { return f.apply(this, arguments); } catch (e) { try { - /* eslint-disable no-console */ + /* eslint-disable-next-line no-console */ console.error('[Rollbar]: Internal error', e); - /* eslint-enable no-console */ } catch (e2) { // Ignore } diff --git a/src/browser/telemetry.js b/src/browser/telemetry.js index 9ddcbb215..735bc6949 100644 --- a/src/browser/telemetry.js +++ b/src/browser/telemetry.js @@ -120,41 +120,46 @@ Instrumenter.prototype.configure = function(options) { } }; -// eslint-disable-next-line complexity Instrumenter.prototype.instrument = function(oldSettings) { - if (this.autoInstrument.network && !(oldSettings && oldSettings.network)) { + var network = oldSettings && oldSettings.network; + if (this.autoInstrument.network && !network) { this.instrumentNetwork(); - } else if (!this.autoInstrument.network && oldSettings && oldSettings.network) { + } else if (!this.autoInstrument.network && network) { this.deinstrumentNetwork(); } - if (this.autoInstrument.log && !(oldSettings && oldSettings.log)) { + var log = oldSettings && oldSettings.log; + if (this.autoInstrument.log && !log) { this.instrumentConsole(); - } else if (!this.autoInstrument.log && oldSettings && oldSettings.log) { + } else if (!this.autoInstrument.log && log) { this.deinstrumentConsole(); } - if (this.autoInstrument.dom && !(oldSettings && oldSettings.dom)) { + var dom = oldSettings && oldSettings.dom; + if (this.autoInstrument.dom && !dom) { this.instrumentDom(); - } else if (!this.autoInstrument.dom && oldSettings && oldSettings.dom) { + } else if (!this.autoInstrument.dom && dom) { this.deinstrumentDom(); } - if (this.autoInstrument.navigation && !(oldSettings && oldSettings.navigation)) { + var navigation = oldSettings && oldSettings.navigation; + if (this.autoInstrument.navigation && !navigation) { this.instrumentNavigation(); - } else if (!this.autoInstrument.navigation && oldSettings && oldSettings.navigation) { + } else if (!this.autoInstrument.navigation && navigation) { this.deinstrumentNavigation(); } - if (this.autoInstrument.connectivity && !(oldSettings && oldSettings.connectivity)) { + var connectivity = oldSettings && oldSettings.connectivity; + if (this.autoInstrument.connectivity && !connectivity) { this.instrumentConnectivity(); - } else if (!this.autoInstrument.connectivity && oldSettings && oldSettings.connectivity) { + } else if (!this.autoInstrument.connectivity && connectivity) { this.deinstrumentConnectivity(); } - if (this.autoInstrument.contentSecurityPolicy && !(oldSettings && oldSettings.contentSecurityPolicy)) { + var contentSecurityPolicy = oldSettings && oldSettings.contentSecurityPolicy; + if (this.autoInstrument.contentSecurityPolicy && !contentSecurityPolicy) { this.instrumentContentSecurityPolicy(); - } else if (!this.autoInstrument.contentSecurityPolicy && oldSettings && oldSettings.contentSecurityPolicy) { + } else if (!this.autoInstrument.contentSecurityPolicy && contentSecurityPolicy) { this.deinstrumentContentSecurityPolicy(); } }; @@ -222,9 +227,7 @@ Instrumenter.prototype.instrumentNetwork = function() { }, this.replacements, 'network'); replace(xhrp, 'send', function(orig) { - /* eslint-disable no-unused-vars */ return function(data) { - /* eslint-enable no-unused-vars */ var xhr = this; function onreadystatechangeHandler() { @@ -331,9 +334,8 @@ Instrumenter.prototype.instrumentNetwork = function() { if ('fetch' in this._window) { replace(this._window, 'fetch', function(orig) { - /* eslint-disable no-unused-vars */ + /* eslint-disable-next-line no-unused-vars */ return function(fn, t) { - /* eslint-enable no-unused-vars */ var args = new Array(arguments.length); for (var i=0, len=args.length; i < len; i++) { args[i] = arguments[i];