Skip to content

Commit fe538e0

Browse files
Chan Chak Shingzoracon
authored andcommitted
Add eslint rules space-before-blocks and brace-style (EFForg#17203)
* Add eslint rules space-before-blocks and brace-style * $linter --fix $srcdir
1 parent e6b8bd6 commit fe538e0

File tree

11 files changed

+74
-65
lines changed

11 files changed

+74
-65
lines changed

chromium/.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"indent": ["error", 2, {"outerIIFEBody": 0}],
1313
"no-unused-vars": "error",
1414
"no-undef": "error",
15-
"strict": ["error", "global"]
15+
"strict": ["error", "global"],
16+
"space-before-blocks": ["error"],
17+
"brace-style": ["error"]
1618
},
1719
"globals": {
1820
"exports": true,

chromium/background-scripts/background.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var showCounter = true;
4242
var isExtensionEnabled = true;
4343
let disabledList = new Set();
4444

45-
function initializeStoredGlobals(){
45+
function initializeStoredGlobals() {
4646
return new Promise(resolve => {
4747
store.get({
4848
httpNowhere: false,
@@ -301,11 +301,11 @@ let simpleHTTPNowhereRedirect = new Map();
301301

302302
const cancelUrl = chrome.runtime.getURL("/pages/cancel/index.html");
303303

304-
function redirectOnCancel(shouldCancel, originURL){
304+
function redirectOnCancel(shouldCancel, originURL) {
305305
return shouldCancel ? {redirectUrl: newCancelUrl(originURL)} : {cancel: false};
306306
}
307307

308-
function newCancelUrl(originURL){
308+
function newCancelUrl(originURL) {
309309
return cancelUrl + "?originURL=" + encodeURI(originURL);
310310
}
311311

@@ -553,7 +553,9 @@ function sortSwitchPlanner(tab_id, rewritten) {
553553
var score = activeCount * 100 + passiveCount;
554554
asset_host_list.push([score, activeCount, passiveCount, asset_host]);
555555
}
556-
asset_host_list.sort(function(a,b){return a[0]-b[0];});
556+
asset_host_list.sort(function(a,b) {
557+
return a[0]-b[0];
558+
});
557559
return asset_host_list;
558560
}
559561

@@ -665,8 +667,7 @@ function onErrorOccurred(details) {
665667
details.error.indexOf("Unable to communicate securely with peer: requested domain name does not match the server’s certificate.") == 0 ||
666668
details.error.indexOf("Cannot communicate securely with peer: no common encryption algorithm(s).") == 0 ||
667669
details.error.indexOf("SSL peer has no certificate for the requested DNS name.") == 0
668-
))
669-
{
670+
)) {
670671
let url = new URL(details.url);
671672
if (url.protocol == "https:") {
672673
url.protocol = "http:";
@@ -782,7 +783,7 @@ function enableSwitchPlannerFor(tabId) {
782783
// Listen for connection from the DevTools panel so we can set up communication.
783784
chrome.runtime.onConnect.addListener(function (port) {
784785
if (port.name == "devtools-page") {
785-
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
786+
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
786787
var tabId = message.tabId;
787788

788789
var disableOnCloseCallback = function() {
@@ -815,9 +816,9 @@ chrome.runtime.onConnect.addListener(function (port) {
815816

816817
// This is necessary for communication with the popup in Firefox Private
817818
// Browsing Mode, see https://bugzilla.mozilla.org/show_bug.cgi?id=1329304
818-
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
819+
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
819820

820-
function get_update_channels_generic(update_channels){
821+
function get_update_channels_generic(update_channels) {
821822
let last_updated_promises = [];
822823
for(let update_channel of update_channels) {
823824
last_updated_promises.push(new Promise(resolve => {
@@ -944,7 +945,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
944945
return obj;
945946
}, new Set());
946947

947-
if(update_channel_names.has(message.object)){
948+
if(update_channel_names.has(message.object)) {
948949
return sendResponse(false);
949950
}
950951

@@ -983,8 +984,8 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
983984
store.get({update_channels: []}, item => {
984985
let scope_changed = false;
985986
item.update_channels = item.update_channels.map(update_channel => {
986-
if(update_channel.name == message.object.name){
987-
if(update_channel.scope != message.object.scope){
987+
if(update_channel.name == message.object.name) {
988+
if(update_channel.scope != message.object.scope) {
988989
scope_changed = true;
989990
}
990991
update_channel = message.object;
@@ -1000,7 +1001,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
10001001
// necesssary to avoid a race condition, see #16673
10011002
update.loadUpdateChannelsKeys().then(() => {
10021003
update.resetTimer();
1003-
if(scope_changed){
1004+
if(scope_changed) {
10041005
initializeAllRules();
10051006
}
10061007
sendResponse(true);
@@ -1029,7 +1030,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
10291030
return true;
10301031
},
10311032
is_firefox: () => {
1032-
if(typeof(browser) != "undefined"){
1033+
if(typeof(browser) != "undefined") {
10331034
browser.runtime.getBrowserInfo().then(function(info) {
10341035
if (info.name == "Firefox") {
10351036
sendResponse(true);

chromium/background-scripts/rules.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const nullIterable = Object.create(null, {
2929
const scopes = new Map();
3030

3131
/* Returns the scope object from the map for the given scope string */
32-
function getScope(scope){
32+
function getScope(scope) {
3333
if (!scopes.has(scope)) {
3434
scopes.set(scope, new RegExp(scope));
3535
}
@@ -174,7 +174,7 @@ RuleSet.prototype = {
174174
}
175175

176176
if(this_rules_length > 0) {
177-
for(let x = 0; x < this.rules.length; x++){
177+
for(let x = 0; x < this.rules.length; x++) {
178178
if(this.rules[x].to != ruleset.rules[x].to) {
179179
return false;
180180
}
@@ -431,7 +431,7 @@ RuleSets.prototype = {
431431
}
432432
},
433433

434-
addStoredCustomRulesets: function(){
434+
addStoredCustomRulesets: function() {
435435
return new Promise(resolve => {
436436
this.store.get({
437437
legacy_custom_rulesets: [],
@@ -445,17 +445,17 @@ RuleSets.prototype = {
445445
},
446446

447447
// Load in the legacy custom rulesets, if any
448-
loadCustomRulesets: function(legacy_custom_rulesets){
449-
for(let legacy_custom_ruleset of legacy_custom_rulesets){
448+
loadCustomRulesets: function(legacy_custom_rulesets) {
449+
for(let legacy_custom_ruleset of legacy_custom_rulesets) {
450450
this.loadCustomRuleset(legacy_custom_ruleset);
451451
}
452452
},
453453

454-
loadCustomRuleset: function(ruleset_string){
454+
loadCustomRuleset: function(ruleset_string) {
455455
this.addFromXml((new DOMParser()).parseFromString(ruleset_string, 'text/xml'));
456456
},
457457

458-
setRuleActiveState: async function(ruleset_name, active){
458+
setRuleActiveState: async function(ruleset_name, active) {
459459
if (active == undefined) {
460460
delete this.ruleActiveStates[ruleset_name];
461461
} else {

chromium/background-scripts/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function initialize() {
88
return new Promise(resolve => {
99
if (chrome.storage.sync) {
1010
chrome.storage.sync.set({"sync-set-test": true}, () => {
11-
if(chrome.runtime.lastError){
11+
if(chrome.runtime.lastError) {
1212
setStorage(chrome.storage.local);
1313
} else {
1414
setStorage(chrome.storage.sync);

chromium/background-scripts/update.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function loadUpdateChannelsKeys() {
4141
imported_keys = {};
4242
combined_update_channels = [];
4343

44-
for(let update_channel of combined_update_channels_preflight){
44+
for(let update_channel of combined_update_channels_preflight) {
4545

4646
try{
4747
imported_keys[update_channel.name] = await window.crypto.subtle.importKey(
@@ -88,17 +88,17 @@ async function checkForNewRulesets(update_channel) {
8888
if(timestamp_result.status == 200) {
8989
let rulesets_timestamp = Number(await timestamp_result.text());
9090

91-
if((await store.local.get_promise('rulesets-timestamp: ' + update_channel.name, 0)) < rulesets_timestamp){
91+
if((await store.local.get_promise('rulesets-timestamp: ' + update_channel.name, 0)) < rulesets_timestamp) {
9292
return rulesets_timestamp;
9393
}
9494
}
9595
return false;
9696
}
9797

9898
// Retrieve the timestamp for when a stored ruleset bundle was published
99-
async function getRulesetTimestamps(){
99+
async function getRulesetTimestamps() {
100100
let timestamp_promises = [];
101-
for(let update_channel of combined_update_channels){
101+
for(let update_channel of combined_update_channels) {
102102
timestamp_promises.push(new Promise(async resolve => {
103103
let timestamp = await store.local.get_promise('rulesets-stored-timestamp: ' + update_channel.name, 0);
104104
resolve([update_channel.name, timestamp]);
@@ -135,7 +135,7 @@ async function getNewRulesets(rulesets_timestamp, update_channel) {
135135
// Returns a promise which verifies that the rulesets have a valid EFF
136136
// signature, and if so, stores them and returns true.
137137
// Otherwise, it throws an exception.
138-
function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_channel){
138+
function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_channel) {
139139
return new Promise((resolve, reject) => {
140140
window.crypto.subtle.verify(
141141
{
@@ -154,7 +154,7 @@ function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_chan
154154
const rulesets = new TextDecoder("utf-8").decode(rulesets_byte_array);
155155
const rulesets_json = JSON.parse(rulesets);
156156

157-
if(rulesets_json.timestamp != rulesets_timestamp){
157+
if(rulesets_json.timestamp != rulesets_timestamp) {
158158
reject(update_channel.name + ': Downloaded ruleset had an incorrect timestamp. This may be an attempted downgrade attack. Aborting.');
159159
} else {
160160
await store.local.set_promise('rulesets: ' + update_channel.name, window.btoa(rulesets_gz));
@@ -170,13 +170,13 @@ function verifyAndStoreNewRulesets(new_rulesets, rulesets_timestamp, update_chan
170170
}
171171

172172
// Unzip and apply the rulesets we have stored.
173-
async function applyStoredRulesets(rulesets_obj){
173+
async function applyStoredRulesets(rulesets_obj) {
174174
let rulesets_promises = [];
175-
for(let update_channel of combined_update_channels){
175+
for(let update_channel of combined_update_channels) {
176176
rulesets_promises.push(new Promise(resolve => {
177177
const key = 'rulesets: ' + update_channel.name;
178178
chrome.storage.local.get(key, root => {
179-
if(root[key]){
179+
if(root[key]) {
180180
util.log(util.NOTE, update_channel.name + ': Applying stored rulesets.');
181181

182182
const rulesets_gz = window.atob(root[key]);
@@ -192,14 +192,14 @@ async function applyStoredRulesets(rulesets_obj){
192192
}));
193193
}
194194

195-
function isNotUndefined(subject){
195+
function isNotUndefined(subject) {
196196
return (typeof subject != 'undefined');
197197
}
198198

199199
const channel_results = (await Promise.all(rulesets_promises)).filter(isNotUndefined);
200200

201-
if(channel_results.length > 0){
202-
for(let channel_result of channel_results){
201+
if(channel_results.length > 0) {
202+
for(let channel_result of channel_results) {
203203
rulesets_obj.addFromJson(channel_result.json.rulesets, channel_result.scope);
204204
}
205205
} else {
@@ -215,9 +215,9 @@ async function performCheck() {
215215
store.local.set_promise('last-checked', current_timestamp);
216216

217217
let num_updates = 0;
218-
for(let update_channel of combined_update_channels){
218+
for(let update_channel of combined_update_channels) {
219219
let new_rulesets_timestamp = await checkForNewRulesets(update_channel);
220-
if(new_rulesets_timestamp){
220+
if(new_rulesets_timestamp) {
221221
util.log(util.NOTE, update_channel.name + ': A new ruleset bundle has been released. Downloading now.');
222222
let new_rulesets = await getNewRulesets(new_rulesets_timestamp, update_channel);
223223
try{
@@ -229,7 +229,7 @@ async function performCheck() {
229229
}
230230
}
231231
}
232-
if(num_updates > 0){
232+
if(num_updates > 0) {
233233
background_callback();
234234
}
235235
};
@@ -253,7 +253,7 @@ chrome.storage.onChanged.addListener(async function(changes, areaName) {
253253
let initialCheck,
254254
subsequentChecks;
255255

256-
async function createTimer(){
256+
async function createTimer() {
257257
const time_to_next_check = await timeToNextCheck();
258258

259259
initialCheck = setTimeout(() => {
@@ -262,7 +262,7 @@ async function createTimer(){
262262
}, time_to_next_check * 1000);
263263
}
264264

265-
function destroyTimer(){
265+
function destroyTimer() {
266266
if (initialCheck) {
267267
clearTimeout(initialCheck);
268268
}
@@ -271,7 +271,7 @@ function destroyTimer(){
271271
}
272272
}
273273

274-
async function initialize(store_param, cb){
274+
async function initialize(store_param, cb) {
275275
store = store_param;
276276
background_callback = cb;
277277

chromium/background-scripts/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function ArrayBufferToString(ab) {
6969
let array = new Uint8Array(ab);
7070
let string = "";
7171

72-
for (let byte of array){
72+
for (let byte of array) {
7373
string += String.fromCharCode(byte);
7474
}
7575

chromium/pages/cancel/ux.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
let observer;
66
document.addEventListener("DOMContentLoaded", () => {
77
const explainer = document.querySelector("[data-i18n=cancel_he_blocking_explainer]");
8-
observer = new MutationObserver(() => {replaceLink(explainer)});
8+
observer = new MutationObserver(() => {
9+
replaceLink(explainer)
10+
});
911
if (explainer.innerText.length > 0) {
1012
replaceLink(explainer);
1113
} else {
@@ -14,7 +16,7 @@ document.addEventListener("DOMContentLoaded", () => {
1416
displayURL();
1517
});
1618

17-
function replaceLink(explainer){
19+
function replaceLink(explainer) {
1820
observer.disconnect();
1921
const linkText = chrome.i18n.getMessage("cancel_he_blocking_network");
2022
const link = document.createElement("a");

chromium/pages/debugging-rulesets/ux.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ document.getElementById("save-button").addEventListener("click", e => {
3434
e.preventDefault();
3535
sendMessage("set_option", { debugging_rulesets: cm.getValue() }, () => {
3636
savedTextElement.style.display = "block";
37-
setTimeout(() => { savedTextElement.style.display = "none" }, 1000);
37+
setTimeout(() => {
38+
savedTextElement.style.display = "none"
39+
}, 1000);
3840

3941
valueHasChanged = false;
4042
document.title = savedTitle;

0 commit comments

Comments
 (0)