Skip to content

Commit

Permalink
Add ESLint standard config (#26)
Browse files Browse the repository at this point in the history
* Add ESLint standard config

* Adding semicolons to match SERP
  • Loading branch information
jonathanKingston authored Feb 15, 2021
1 parent 3c067e9 commit 4c99735
Show file tree
Hide file tree
Showing 27 changed files with 2,155 additions and 531 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
privacy-protections/fingerprinting/helpers/diff.js
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "standard",
"rules": {
"indent": ["error", 4],
"semi": ["error", "always"]
},
"env": {
"browser": true
}
}
11 changes: 11 additions & 0 deletions TEMPLATES/complex/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"globals": {
"data": "writable"
},
"parserOptions": {
"sourceType": "script",
"ecmaFeatures": {
"globalReturn": false
}
},
}
24 changes: 12 additions & 12 deletions TEMPLATES/complex/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const tests = [
id: 'test-test',
run: () => {
// function returning either a value or a promise
let resolve, reject;
const promise = new Promise((res, rej) => {resolve = res; reject = rej});
let res;
const promise = new Promise((resolve, reject) => { res = resolve; });

setTimeout(() => resolve('ok'), 1000);
setTimeout(() => res('ok'), 1000);

return promise;
}
Expand All @@ -22,12 +22,12 @@ const tests = [

// object that contains results of all tests
const results = {
page: 'name-of-the-test',// FILL ME OUT!
page: 'name-of-the-test', // FILL ME OUT!
date: null,
results: []
};

function resultToHTML(data) {
function resultToHTML (data) {
if (Array.isArray(data)) {
return `<ul>${data.map(r => `<li>${r.test} - ${r.result}</li>`).join('')}</ul>`;
} else if (data) {
Expand All @@ -40,7 +40,7 @@ function resultToHTML(data) {
/**
* Test runner
*/
function runTests() {
function runTests () {
startButton.setAttribute('disabled', 'disabled');
downloadButton.removeAttribute('disabled');
testsDiv.removeAttribute('hidden');
Expand All @@ -52,7 +52,7 @@ function runTests() {

testsDetailsDiv.innerHTML = '';

function updateSummary() {
function updateSummary () {
testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`;
}

Expand Down Expand Up @@ -85,10 +85,10 @@ function runTests() {
updateSummary();
});
} else {
valueSpan.innerHTML = resultToHTML(data);;
valueSpan.innerHTML = resultToHTML(data);
resultObj.value = result || null;
}
} catch(e) {
} catch (e) {
failed++;
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`;
}
Expand All @@ -101,13 +101,13 @@ function runTests() {
startButton.removeAttribute('disabled');
}

function downloadTheResults() {
function downloadTheResults () {
const data = JSON.stringify(results, null, 2);
const a = document.createElement('a');
const url = window.URL.createObjectURL(new Blob([data], {type: 'application/json'}));
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' }));
a.href = url;
a.download = 'fingerprinting-results.json';

document.body.appendChild(a);
a.click();

Expand Down
30 changes: 16 additions & 14 deletions features/stack-tracing/script.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* globals log */

(() => {
let base = new URL(document.currentScript.src);
let party = base.origin == window.top.location.origin ? 'first' : 'third';
let scriptName = `${party} party script`;
const base = new URL(document.currentScript.src);
const party = base.origin === window.top.location.origin ? 'first' : 'third';
const scriptName = `${party} party script`;

log(scriptName, new Error().stack);
log(scriptName, new Error().stack);

let worker = new Worker('./worker.js');
worker.addEventListener('message', msg => {
let { source, stackValue } = msg.data;
log(`${scriptName} loading ${source}`, stackValue);
});
worker.postMessage({ action: 'setup' });
const worker = new Worker('./worker.js');
worker.addEventListener('message', msg => {
const { source, stackValue } = msg.data;
log(`${scriptName} loading ${source}`, stackValue);
});
worker.postMessage({ action: 'setup' });

setTimeout(() => {
log(`${scriptName} setTimeout`, new Error().stack);
}, 0)
setTimeout(() => {
log(`${scriptName} setTimeout`, new Error().stack);
}, 0);

document.write(`<script>log('${scriptName} write', new Error().stack);</script>`);
document.write(`<script>log('${scriptName} write', new Error().stack);</script>`);
})();
20 changes: 10 additions & 10 deletions features/stack-tracing/worker.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function log(source, stackValue) {
postMessage({ source, stackValue });
function log (source, stackValue) {
postMessage({ source, stackValue });
}

self.addEventListener('message', msg => {
if (msg.data.action && msg.data.action === 'setup') {
setup();
}
if (msg.data.action && msg.data.action === 'setup') {
setup();
}
});

function setup() {
log("worker", new Error().stack)
function setup () {
log('worker', new Error().stack);

setTimeout(() => {
log("worker setTimeout", new Error().stack)
}, 0);
setTimeout(() => {
log('worker setTimeout', new Error().stack);
}, 0);
}
Loading

0 comments on commit 4c99735

Please sign in to comment.