mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Introduce Eslint to validate style
This patch introduces eslint and fixes multiple minor code style issues.
This commit is contained in:
parent
2b50d8cc32
commit
1f51384918
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
||||
third_party/*
|
||||
examples/*
|
124
.eslintrc.js
Normal file
124
.eslintrc.js
Normal file
@ -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]
|
||||
}
|
||||
};
|
@ -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.
|
||||
|
16
lib/.eslintrc.js
Normal file
16
lib/.eslintrc.js
Normal file
@ -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,
|
||||
}
|
||||
};
|
@ -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();
|
||||
|
@ -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',
|
||||
|
@ -87,4 +87,4 @@ var helpers = module.exports = {
|
||||
code += `\n//# sourceURL=${sourceURL}`;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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 = {
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -29,5 +29,4 @@ module.exports = {
|
||||
throw error;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user