Add eslint capability with an initial set of rules, and get the add-ons passing. (#1). r=felipc

This commit is contained in:
Mark Banner 2016-11-11 14:42:04 +00:00 коммит произвёл GitHub
Родитель d15b35f4ec
Коммит d455dd0bf8
7 изменённых файлов: 406 добавлений и 65 удалений

2
.eslintignore Normal file
Просмотреть файл

@ -0,0 +1,2 @@
!.eslintrc.js
node_modules

271
.eslintrc.js Normal file
Просмотреть файл

@ -0,0 +1,271 @@
"use strict";
/* eslint-env node */
module.exports = {
// When adding items to this file please check for effects on sub-directories.
"parserOptions": {"ecmaFeatures": {"jsx": true}},
"env": {
"browser": true,
"es6": true,
"mocha": true
},
"globals": {
"Components": false,
"APP_SHUTDOWN": false
},
"plugins": [
"json",
"mozilla",
"promise"
],
"extends": [
"eslint:recommended"
],
"rules": {
"mozilla/import-globals": "warn",
"promise/always-return": "error",
"promise/catch-or-return": "error",
"promise/param-names": "error",
"accessor-pairs": ["error", {"setWithoutGet": true, "getWithoutSet": false}],
"array-bracket-spacing": ["error", "never"],
"array-callback-return": "error",
"arrow-body-style": ["error", "as-needed"],
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": "error",
"block-scoped-var": "error",
"block-spacing": ["error", "never"],
"brace-style": "off",
"callback-return": "off",
"camelcase": "off",
"comma-dangle": ["error", "never"],
"comma-spacing": "error",
"comma-style": "error",
"complexity": ["error", {"max": 20}],
"computed-property-spacing": ["error", "never"],
"consistent-return": "error",
"consistent-this": ["error", "use-bind"],
"constructor-super": "error",
"curly": ["error", "all"],
"default-case": "off",
"dot-location": ["error", "property"],
"dot-notation": "error",
"eol-last": "error",
"func-names": "off",
"func-style": "off",
"generator-star-spacing": ["error", {"before": false, "after": false}],
"global-require": "off",
"guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "off",
"id-length": "off",
"id-match": "off",
"indent": ["error", 2, {"SwitchCase": 1}],
"init-declarations": "off",
"jsx-quotes": ["error", "prefer-double"],
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
"keyword-spacing": "error",
"linebreak-style": ["error", "unix"],
"lines-around-comment": ["error", {
"beforeBlockComment": true,
"allowObjectStart": true
}],
"max-depth": ["error", 4],
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": ["error", 4],
"max-params": ["error", 6],
"max-statements": ["error", 50],
"max-statements-per-line": ["error", {"max": 2}],
"multiline-ternary": "off",
"new-cap": ["error", {"newIsCap": true, "capIsNew": false}],
"new-parens": "error",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": ["error", {"ignoreChainWithDepth": 3}],
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "off",
"no-caller": "error",
"no-case-declarations": "error",
"no-catch-shadow": "error",
"no-class-assign": "error",
"no-cond-assign": "error",
"no-confusing-arrow": "error",
"no-console": "error",
"no-const-assign": "error",
"no-constant-condition": "error",
"no-continue": "off",
"no-control-regex": "error",
"no-debugger": "error",
"no-delete-var": "error",
"no-div-regex": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-else-return": "error",
"no-empty": "error",
"no-empty-character-class": "error",
"no-empty-function": "off",
"no-empty-pattern": "error",
"no-eq-null": "error",
"no-eval": "error",
"no-ex-assign": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-boolean-cast": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-extra-semi": "error",
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-func-assign": "error",
"no-implicit-coercion": ["error", {"allow": ["!!"]}],
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": "error",
"no-invalid-regexp": "error",
"no-invalid-this": "off",
"no-irregular-whitespace": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": ["error", {
"allowSamePrecedence": true,
"groups": [
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
]
}],
"no-mixed-requires": "error",
"no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": ["error", {"max": 1, "maxBOF": 0, "maxEOF": 0}],
"no-native-reassign": "error",
"no-negated-condition": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-obj-calls": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-param-reassign": "error",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "off",
"no-process-exit": "error",
"no-proto": "error",
"no-prototype-builtins": "error",
"no-redeclare": "error",
"no-regex-spaces": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-syntax": "error",
"no-return-assign": ["error", "except-parens"],
"no-script-url": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off", // TODO: Change to `1`?
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sparse-arrays": "error",
"no-sync": "error",
"no-tabs": "error",
"no-ternary": "off",
"no-this-before-super": "error",
"no-throw-literal": "error",
"no-trailing-spaces": ["error", {"skipBlankLines": false}],
"no-undef": "error",
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unexpected-multiline": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-unused-vars": ["error", {
"vars": "all",
"varsIgnorePattern": "^Cc|Ci|Cu|Cr|EXPORTED_SYMBOLS",
"args": "none"
}],
"no-use-before-define": "error",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "off", // TODO: Change to `1`?
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": ["error", {"multiline": true}],
"object-curly-spacing": ["error", "never"],
"object-property-newline": ["error", {"allowMultiplePropertiesPerLine": true}],
"object-shorthand": ["error", "always"],
"one-var": ["error", "never"],
"one-var-declaration-per-line": ["error", "initializations"],
"operator-assignment": ["error", "always"],
"operator-linebreak": ["error", "after"],
"padded-blocks": ["error", "never"],
"prefer-arrow-callback": ["error", {"allowNamedFunctions": true}],
"prefer-const": "off",
"prefer-reflect": "off",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quote-props": ["error", "consistent"],
"quotes": ["error", "double", "avoid-escape"],
"radix": ["error", "always"],
"require-jsdoc": "off",
"require-yield": "error",
"rest-spread-spacing": ["error", "never"],
"semi": ["error", "always"],
"semi-spacing": ["error", {"before": false, "after": true}],
"sort-imports": "error",
"sort-vars": "error",
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": ["error", "always"],
"strict": "off",
"template-curly-spacing": ["error", "never"],
"unicode-bom": ["error", "never"],
"use-isnan": "error",
"valid-jsdoc": ["off", {
"requireReturn": false,
"requireParamDescription": false,
"requireReturnDescription": false
}],
"valid-typeof": "error",
"wrap-iife": ["error", "inside"],
"wrap-regex": "off",
"yield-star-spacing": ["error", "after"],
"yoda": ["error", "never"]
}
};

1
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
node_modules

Просмотреть файл

@ -9,7 +9,7 @@ Some [original documentation](https://pad.mocotoolsprod.net/gofaster_oneoffaddon
## What is this repository?
This repository should be used as a resource for developers to quickly develop and test one off system add-ons. If you would like to deploy a fix or update as a system add-on, we ask that you use this repository to host your code and get it reviewed.
This repository should be used as a resource for Firefox developers to quickly develop and test one off system add-ons. If you would like to deploy a fix or update as a system add-on, we ask that you use this repository to host your code and get it reviewed.
## What is the criteria for a "One Off System Add-on"?
@ -19,6 +19,30 @@ These are things that are primarily fixes and updates we would like to deploy to
Look here: https://wiki.mozilla.org/Firefox/Go_Faster/System_Add-ons/Process#Where_can_I_find_existing_examples_of_system_add-ons.3F
## Review Requirements
Generally, changes to this repository should have a review from a
[Firefox peer](https://wiki.mozilla.org/Modules/Firefox). If the add-on relates
to a platform change, then it should have review from an appropriate peer of that
area.
## Tests
Currently only eslint is enabled on the repository, however we hope to have
a unit/functional test harness soon.
To get the required dependencies:
```shell
npm install
```
The tests can be run with:
```shell
npm test
```
## Todo
* history of the things we launched - with bugs.
@ -26,7 +50,7 @@ Look here: https://wiki.mozilla.org/Firefox/Go_Faster/System_Add-ons/Process#Whe
* Tagging?
* Examples?/Samples? (our current stock of things should be enough)
* add-ons!
* Tests: lint, functional/integration (selenium?)
* Tests: functional/integration (selenium?)
* Scripts?
* Packaging add-ons
* Running add-on (or combinations of add-ons)

15
addons/asyncrendering/bootstrap.js поставляемый
Просмотреть файл

@ -3,21 +3,22 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* exported install, uninstall, startup, shutdown */
/* eslint no-implicit-globals: "off" */
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Preferences.jsm");
const {Preferences} = Cu.import("resource://gre/modules/Preferences.jsm", this);
const PREF_ASYNC_DRAWING_ENABLED = "dom.ipc.plugins.asyncdrawing.enabled";
function install() {
}
function install() {}
function uninstall() {
}
function uninstall() {}
function startup() {
let defaults = new Preferences({defaultBranch: true})
let defaults = new Preferences({defaultBranch: true});
defaults.set(PREF_ASYNC_DRAWING_ENABLED, true);
}
function shutdown(data, reason) {
function shutdown(data, reason) {}

127
addons/outofdate-notifications/bootstrap.js поставляемый
Просмотреть файл

@ -3,71 +3,61 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* exported install, uninstall, startup, shutdown */
/* eslint no-implicit-globals: "off" */
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import('resource://gre/modules/TelemetryController.jsm');
Cu.import("resource://gre/modules/TelemetryController.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {
return Services.strings.createBundle("chrome://outofdate-notifications/" +
"locale/" +
"outofdate-notifications.properties");
});
XPCOMUtils.defineLazyGetter(this, "gStringBundle", () =>
Services.strings.createBundle("chrome://outofdate-notifications/" +
"locale/" +
"outofdate-notifications.properties")
);
const PREF_UPDATE_URL = "app.update.url.manual";
const PREF_UPDATE_URL = "app.update.url.manual";
const PREF_UPDATE_DEFAULT_URL = "https://www.mozilla.org/firefox";
const KNOWN_DISTROS = ["1und1",
"acer",
"aol",
"bing",
"gmx",
"mail.com",
"toshiba",
"webde",
"yandex",
"yahoo"];
const KNOWN_DISTROS = [
"1und1",
"acer",
"aol",
"bing",
"gmx",
"mail.com",
"toshiba",
"webde",
"yandex",
"yahoo"
];
let gPingTypes = [{ payload: { event: "started" }, sent: false },
{ payload: { event: "shown" }, sent: false },
{ payload: { event: "clicked" }, sent: false }];
let gPingTypes = [
{
payload: {event: "started"},
sent: false
},
{
payload: {event: "shown"},
sent: false
},
{
payload: {event: "clicked"},
sent: false
}];
let gIsPartnerRepack = false;
function sendPing(aPingIndex) {
if (!gPingTypes[aPingIndex].sent) {
TelemetryController.submitExternalPing(
"outofdate-notifications-system-addon", gPingTypes[aPingIndex].payload,
{ addClientId: true });
{addClientId: true});
gPingTypes[aPingIndex].sent = true;
}
}
function startup() {
// Don't run this addon for partner repacks.
let defaultPrefs = new Preferences({ defaultBranch: true });
let distroId = defaultPrefs.get("distribution.id", "not-repack");
for (let d of KNOWN_DISTROS) {
if (d === distroId.substring(0, d.length)) {
gIsPartnerRepack = true;
return;
}
}
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
// Load into any existing windows
let browserWindow = wm.getMostRecentWindow("navigator:browser");
loadIntoWindow(browserWindow);
// Load into any new windows
wm.addListener(windowListener);
sendPing(0);
}
function showDoorhanger(aWindow) {
if (!aWindow || !aWindow.gBrowser) {
return;
@ -75,15 +65,15 @@ function showDoorhanger(aWindow) {
let message = gStringBundle.GetStringFromName("message");
let buttons = [
{
label: gStringBundle.GetStringFromName("buttonlabel"),
accessKey: gStringBundle.GetStringFromName("buttonaccesskey"),
callback: function () {
label: gStringBundle.GetStringFromName("buttonlabel"),
accessKey: gStringBundle.GetStringFromName("buttonaccesskey"),
callback() {
sendPing(2);
let url = Preferences.get(PREF_UPDATE_URL, PREF_UPDATE_DEFAULT_URL);
aWindow.openUILinkIn(url, "tab");
}
},
}
];
let box =
aWindow.document.getElementById("high-priority-global-notificationbox");
@ -123,21 +113,46 @@ function unloadFromWindow(aWindow) {
box.removeNotification(notification);
}
var windowListener = {
onOpenWindow: function(aWindow) {
let windowListener = {
onOpenWindow(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
domWindow.addEventListener("load", function() {
domWindow.removeEventListener("load", arguments.callee, false);
domWindow.addEventListener("load", function loadListener() {
domWindow.removeEventListener("load", loadListener, false);
loadIntoWindow(domWindow);
}, false);
},
onCloseWindow: function(aWindow) {},
onWindowTitleChange: function(aWindow, aTitle) {}
onCloseWindow(aWindow) {},
onWindowTitleChange(aWindow, aTitle) {}
};
function startup() {
// Don't run this addon for partner repacks.
let defaultPrefs = new Preferences({defaultBranch: true});
let distroId = defaultPrefs.get("distribution.id", "not-repack");
for (let d of KNOWN_DISTROS) {
if (d === distroId.substring(0, d.length)) {
gIsPartnerRepack = true;
return;
}
}
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
// Load into any existing windows
let browserWindow = wm.getMostRecentWindow("navigator:browser");
loadIntoWindow(browserWindow);
// Load into any new windows
wm.addListener(windowListener);
sendPing(0);
}
function shutdown(aData, aReason) {
// When the application is shutting down we normally don't have to clean
// up any UI changes made

27
package.json Normal file
Просмотреть файл

@ -0,0 +1,27 @@
{
"name": "one-off-system-add-ons",
"version": "0.0.1",
"description": "Repository for one-off Firefox system add-ons.",
"repository": {
"type": "git",
"url": "git@github.com:mozilla/one-off-system-add-ons.git"
},
"bugs": {
"url": "https://bugzilla.mozilla.org"
},
"engines": {
"firefox": ">=48.0a1"
},
"dependencies": {},
"devDependencies": {
"eslint": "3.9.1",
"eslint-plugin-json": "1.2.0",
"eslint-plugin-mozilla": "0.2.3",
"eslint-plugin-promise": "3.3.1"
},
"scripts": {
"lint": "eslint --ext=.js,.json .",
"test": "npm run lint"
},
"license": "MPL-2.0"
}