diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000000..bffeae191ff --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +third_party/* +examples/* diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..7014f72191a --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,124 @@ +module.exports = { + "root": true, + + "env": { + "node": true, + "es6": true + }, + + "parserOptions": { + "ecmaVersion": 8 + }, + + /** + * ESLint rules + * + * All available rules: http://eslint.org/docs/rules/ + * + * Rules take the following form: + * "rule-name", [severity, { opts }] + * Severity: 2 == error, 1 == warning, 0 == off. + */ + "rules": { + /** + * Enforced rules + */ + + + // syntax preferences + "quotes": [2, "single", { + "avoidEscape": true, + "allowTemplateLiterals": true + }], + "semi": 2, + "no-extra-semi": 2, + "comma-style": [2, "last"], + "wrap-iife": [2, "inside"], + "spaced-comment": [2, "always", { + "markers": ["*"] + }], + "eqeqeq": [2], + "arrow-body-style": [2, "as-needed"], + "accessor-pairs": [2, { + "getWithoutSet": false, + "setWithoutGet": false + }], + "curly": [2, "multi-or-nest", "consistent"], + "new-parens": 2, + "func-call-spacing": 2, + "arrow-parens": [2, "as-needed"], + + // anti-patterns + "no-with": 2, + "no-multi-str": 2, + "no-caller": 2, + "no-implied-eval": 2, + "no-labels": 2, + "no-new-object": 2, + "no-octal-escape": 2, + "no-self-compare": 2, + "no-shadow-restricted-names": 2, + "no-cond-assign": 2, + "no-debugger": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty-character-class": 2, + "no-unreachable": 2, + "no-unsafe-negation": 2, + "radix": 2, + "valid-typeof": 2, + "no-unused-vars": [2, { "args": "none", "vars": "local" }], + + // es2015 features + "require-yield": 2, + "template-curly-spacing": [2, "never"], + + // spacing details + "space-infix-ops": 2, + "space-in-parens": [2, "never"], + "space-before-function-paren": [2, "never"], + "no-whitespace-before-property": 2, + "keyword-spacing": [2, { + "overrides": { + "if": {"after": true}, + "else": {"after": true}, + "for": {"after": true}, + "while": {"after": true}, + "do": {"after": true}, + "switch": {"after": true}, + "return": {"after": true} + } + }], + "arrow-spacing": [2, { + "after": true, + "before": true + }], + + // file whitespace + "no-multiple-empty-lines": [2, {"max": 2}], + "no-mixed-spaces-and-tabs": 2, + "no-trailing-spaces": 2, + "linebreak-style": [ 2, "unix" ], + + /** + * Disabled, aspirational rules + */ + + "indent": [0, 4, { "SwitchCase": 1, "CallExpression": {"arguments": 2}, "MemberExpression": 2 }], + + // brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions + "brace-style": [0, "allman", { "allowSingleLine": true }], + + // key-spacing is disabled, as some objects use value-aligned spacing, some not. + "key-spacing": [0, { + "beforeColon": false, + "afterColon": true, + "align": "value" + }], + // quote-props is diabled, as property quoting styles are too varied to enforce. + "quote-props": [0, "as-needed"], + + // no-implicit-globals will prevent accidental globals + "no-implicit-globals": [0] + } +}; diff --git a/install.js b/install.js index f7084ae8617..588a393faca 100644 --- a/install.js +++ b/install.js @@ -16,7 +16,6 @@ var Downloader = require('./utils/ChromiumDownloader'); var revision = require('./package').puppeteer.chromium_revision; -var fs = require('fs'); var ProgressBar = require('progress'); // Do nothing if the revision is already downloaded. diff --git a/lib/.eslintrc.js b/lib/.eslintrc.js new file mode 100644 index 00000000000..1d9df6e7f93 --- /dev/null +++ b/lib/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + "extends": "../.eslintrc.js", + /** + * ESLint rules + * + * All available rules: http://eslint.org/docs/rules/ + * + * Rules take the following form: + * "rule-name", [severity, { opts }] + * Severity: 2 == error, 1 == warning, 0 == off. + */ + "rules": { + "no-console": [2, { "allow": ["warn", "error", "assert", "timeStamp", "time", "timeEnd"] }], + "no-debugger": 0, + } +}; diff --git a/lib/Browser.js b/lib/Browser.js index 905462b61fd..25654687aee 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -130,13 +130,12 @@ function waitForChromeResponsive(remoteDebuggingPort) { path: '/json/list' }; var probeTimeout = 100; - var probeAttempt = 1; sendRequest(); return promise; function sendRequest() { var req = http.request(options, res => { - fulfill() + fulfill(); }); req.on('error', e => setTimeout(sendRequest, probeTimeout)); req.end(); diff --git a/lib/Page.js b/lib/Page.js index cd5599945fc..e3a08e20416 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -208,10 +208,8 @@ class Page extends EventEmitter { _handleException(exceptionDetails) { var stack = []; - if (exceptionDetails.stackTrace) { + if (exceptionDetails.stackTrace) stack = exceptionDetails.stackTrace.callFrames.map(cf => cf.url); - } - var stackTrace = exceptionDetails.stackTrace; this.emit(Page.Events.Exception, exceptionDetails.exception.description, stack); } @@ -545,7 +543,7 @@ function convertPrintParameterToInches(parameter) { throw new Error('printToPDF Cannot handle parameter type: ' + (typeof parameter)); } return pixels / 96; -}; +} Page.Events = { Alert: 'alert', diff --git a/lib/helpers.js b/lib/helpers.js index f71c98b4db6..4930699bd6b 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -87,4 +87,4 @@ var helpers = module.exports = { code += `\n//# sourceURL=${sourceURL}`; return code; } -} +}; diff --git a/phantomjs/Phantom.js b/phantomjs/Phantom.js index ed0269681ee..e1fdec631dc 100644 --- a/phantomjs/Phantom.js +++ b/phantomjs/Phantom.js @@ -121,13 +121,13 @@ module.exports.create = function(context, scriptPath) { */ loadModule: function(moduleSource, filename) { var code = [ - "(function(require, exports, module) {\n", + '(function(require, exports, module) {\n', moduleSource, - "\n}.call({},", - "require.cache['" + filename + "']._getRequire(),", - "require.cache['" + filename + "'].exports,", - "require.cache['" + filename + "']", - "));" + '\n}.call({},', + 'require.cache[\'' + filename + '\']._getRequire(),', + 'require.cache[\'' + filename + '\'].exports,', + 'require.cache[\'' + filename + '\']', + '));' ].join(''); vm.runInContext(code, context, { filename: filename, @@ -136,4 +136,4 @@ module.exports.create = function(context, scriptPath) { }, }; return phantom; -} +}; diff --git a/phantomjs/System.js b/phantomjs/System.js index 770929350ba..c6187267991 100644 --- a/phantomjs/System.js +++ b/phantomjs/System.js @@ -29,7 +29,7 @@ class System { this.stdin = new StandardInput(process.stdin); this.stdout = new StandardOutput(process.stdout); this.stderr = new StandardOutput(process.stderr); - this.platform = "phantomjs"; + this.platform = 'phantomjs'; this.pid = process.pid; this.isSSLSupported = false; this.os = { diff --git a/phantomjs/WebPage.js b/phantomjs/WebPage.js index d658b5cb2e3..38662f852e9 100644 --- a/phantomjs/WebPage.js +++ b/phantomjs/WebPage.js @@ -18,10 +18,7 @@ var await = require('./utilities').await; var EventEmitter = require('events'); var fs = require('fs'); var path = require('path'); -var mime = require('mime'); - var PageEvents = require('../lib/Page').Events; -var ScreenshotTypes = require('../lib/Page').ScreenshotTypes; var noop = function() { }; @@ -42,9 +39,7 @@ class WebPage { if (options.viewportSize) await(this._page.setSize(options.viewportSize)); - await(this._page.setInPageCallback('callPhantom', (...args) => { - return this.onCallback.apply(null, args); - })); + await(this._page.setInPageCallback('callPhantom', (...args) => this.onCallback.apply(null, args))); this.clipRect = options.clipRect || {left: 0, top: 0, width: 0, height: 0}; this.onCallback = null; diff --git a/phantomjs/WebServer.js b/phantomjs/WebServer.js index 4d99b3246d7..320243f46d6 100644 --- a/phantomjs/WebServer.js +++ b/phantomjs/WebServer.js @@ -22,7 +22,7 @@ class WebServer { this._server = http.createServer(); this.objectName = 'WebServer'; this.listenOnPort = this.listen; - this.newRequest = function(req, res) { } + this.newRequest = function(req, res) { }; Object.defineProperty(this, 'port', { get: () => { if (!this._server.listening) @@ -64,10 +64,10 @@ class WebServer { }); } res.header = res.getHeader; - res.setHeaders = (headers) => { + res.setHeaders = headers => { for (var key in headers) res.setHeader(key, headers[key]); - } + }; Object.defineProperty(res, 'statusCode', { enumerable: true, configurable: true, diff --git a/phantomjs/index.js b/phantomjs/index.js index 4dca15dfd02..e563ce37479 100644 --- a/phantomjs/index.js +++ b/phantomjs/index.js @@ -44,7 +44,7 @@ module.exports = { context.phantom = Phantom.create(context, scriptPath); context.console = console; context.window = context; - context.WebPage = (options) => new WebPage(browser, scriptPath, options); + context.WebPage = options => new WebPage(browser, scriptPath, options); vm.createContext(context); @@ -67,5 +67,5 @@ module.exports = { })(nativeExports); return context; } -} +}; diff --git a/phantomjs/utilities.js b/phantomjs/utilities.js index 9663d196611..46ee945ce7f 100644 --- a/phantomjs/utilities.js +++ b/phantomjs/utilities.js @@ -29,5 +29,4 @@ module.exports = { throw error; return result; } -} - +}; diff --git a/utils/check_availability.js b/utils/check_availability.js index 58db579cc04..8a3501beec3 100755 --- a/utils/check_availability.js +++ b/utils/check_availability.js @@ -20,10 +20,10 @@ var https = require('https'); var OMAHA_PROXY = 'https://omahaproxy.appspot.com/all.json'; var colors = { - reset: "\x1b[0m", - red: "\x1b[31m", - green: "\x1b[32m", - yellow: "\x1b[33m" + reset: '\x1b[0m', + red: '\x1b[31m', + green: '\x1b[32m', + yellow: '\x1b[33m' }; class Table {