Skip to content

Commit

Permalink
ESLint, with the Google config
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick committed Dec 11, 2015
1 parent b2b385d commit 5c20f8d
Show file tree
Hide file tree
Showing 56 changed files with 348 additions and 375 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_site/
service-worker/serviceworker-cache-polyfill.js
decorators-es7/
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "google",
"env": {
"browser": true
},
"globals": {
"ChromeSamples": true
},
"rules": {
"require-jsdoc": 0,
"no-inline-comments": 0
}
}
27 changes: 0 additions & 27 deletions .jshintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: ruby
rvm:
- 2.1
script:
- bundle exec jekyll build
- npm install
- gulp lint
- npm run lint
- bundle exec jekyll build
branches:
only:
- /.*/
Expand Down
2 changes: 0 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ exclude:
- README.md
- node_modules
- Gemfile
- gulpfile.js
- linter.rb
- vendor
7 changes: 7 additions & 0 deletions array-methods-es6/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rules": {
"no-unused-vars": 0,
"no-undef": 0,
"space-infix-ops": 0
}
}
2 changes: 1 addition & 1 deletion array-methods-es6/demo2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var divs = document.querySelectorAll("div");
var divs = document.querySelectorAll('div');
Array.from(divs).forEach(function(node) {
console.log(node);
});
2 changes: 1 addition & 1 deletion array-methods-es6/demo5.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[0, 1, 2, 3, 4].copyWithin(target=0, start=3, end=4); // [3, 1, 2, 3, 4]
[0, 1, 2, 3, 4].copyWithin(target=0, start=3, end=4); // [3, 1, 2, 3, 4]
[0, 1, 2, 3, 4].copyWithin(target=0, start=-2, end=-1); // [3, 1, 2, 3, 4]
4 changes: 3 additions & 1 deletion array-methods-es6/demo7.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function startsWithLetterA(element, index, array) {
if (element.startsWith('a')) return element;
if (element.startsWith('a')) {
return element;
}
}
var cuteNames = ['jeff', 'marc', 'addy', 'francois'];

Expand Down
4 changes: 3 additions & 1 deletion array-methods-es6/demo8.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function startsWithLetterA(element, index, array) {
if (element.startsWith('a')) return element;
if (element.startsWith('a')) {
return element;
}
}
var cuteNames = ['jeff', 'marc', 'addy', 'francois'];

Expand Down
4 changes: 3 additions & 1 deletion arrows-es6/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ ChromeSamples.log(add(3, 4));
// `return` is implied if using an expression after an arrow.
let developers = [{name: 'Rob'}, {name: 'Jake'}];
// Before...
let es5Output = developers.map(function(developer) { return developer.name; });
let es5Output = developers.map(function(developer) {
return developer.name;
});
ChromeSamples.log(es5Output);

// After...
Expand Down
21 changes: 13 additions & 8 deletions battery-status/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function updateBatteryUI(battery) {
chargingTimeEl.textContent = battery.chargingTime + ' Seconds';
dichargeTimeEl.textContent = battery.dischargingTime + ' Seconds';

if(battery.charging === true) {
if (battery.charging === true) {
chargingStateEl.textContent = 'Charging';
} else if(battery.charging === false) {
} else if (battery.charging === false) {
chargingStateEl.textContent = 'Discharging';
}
}
Expand All @@ -20,14 +20,19 @@ function monitorBattery(battery) {
updateBatteryUI(battery);

// Monitor for futher updates.
battery.addEventListener('levelchange', updateBatteryUI.bind(null, battery));
battery.addEventListener('chargingchange', updateBatteryUI.bind(null, battery));
battery.addEventListener('dischargingtimechange', updateBatteryUI.bind(null, battery));
battery.addEventListener('chargingtimechange', updateBatteryUI.bind(null, battery));
battery.addEventListener('levelchange',
updateBatteryUI.bind(null, battery));
battery.addEventListener('chargingchange',
updateBatteryUI.bind(null, battery));
battery.addEventListener('dischargingtimechange',
updateBatteryUI.bind(null, battery));
battery.addEventListener('chargingtimechange',
updateBatteryUI.bind(null, battery));
}

if('getBattery' in navigator) {
if ('getBattery' in navigator) {
navigator.getBattery().then(monitorBattery);
} else {
ChromeSamples.setStatus('The Battery Status API is not supported on this platform.');
ChromeSamples.setStatus('The Battery Status API is not supported on ' +
'this platform.');
}
29 changes: 15 additions & 14 deletions classes-es6/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class Polygon {
}

sayHistory() {
ChromeSamples.log('"Polygon" is derived from the Greek polus (many) and gonia (angle).');
ChromeSamples.log('"Polygon" is derived from the Greek polus (many) ' +
'and gonia (angle).');
}

// We will look at static and subclassed methods shortly
}

// Classes are used just like ES5 constructor functions:
let p = new Polygon(300,400);
let p = new Polygon(300, 400);
p.sayName();
ChromeSamples.log('The width of this polygon is ' + p.width);


// Example 2: Creating a new class (expression-form)
// ===============================================================

Expand All @@ -41,14 +41,14 @@ ChromeSamples.log('The width of this polygon is ' + p.width);
// of defining a new class. For example:
const MyPoly = class Poly {
getPolyName() {
ChromeSamples.log('Hi. I was created with a Class expression. My name is ' + Poly.name);
ChromeSamples.log('Hi. I was created with a Class expression. My name is ' +
Poly.name);
}
};

let inst = new MyPoly();
inst.getPolyName();


// Example 3: Extending an existing class
// ===============================================================

Expand Down Expand Up @@ -114,7 +114,7 @@ class Tripple {
// Using the 'static' keyword creates a method which is associated
// with a class, but not with an instance of the class.
static tripple(n) {
n = n | 1;
n = n || 1;
return n * 3;
}
}
Expand All @@ -130,26 +130,27 @@ class BiggerTripple extends Tripple {
ChromeSamples.log(Tripple.tripple());
ChromeSamples.log(Tripple.tripple(6));
ChromeSamples.log(BiggerTripple.tripple(3));
var tp = new Tripple();
// var tp = new Tripple();
// ChromeSamples.log(tp.tripple()); tp.tripple is not a function


// Example 6: Subclassing built-in classes and DOM
// ===============================================================

// Extend Date built-in
class myDate extends Date {
class MyDate extends Date {
constructor() {
super();
}

getFormattedDate() {
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
return this.getDate() + "-" + months[this.getMonth()] + "-" + this.getFullYear();
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'];
return this.getDate() + '-' + months[this.getMonth()] + '-' +
this.getFullYear();
}
}

var aDate = new myDate();
var aDate = new MyDate();
ChromeSamples.log(aDate.getTime());
ChromeSamples.log(aDate.getFormattedDate());

Expand All @@ -166,7 +167,7 @@ var eua = new ExtendedUint8Array();
ChromeSamples.log(eua.byteLength);

// Extend DOM Audio element
class myAudio extends Audio {
class MyAudio extends Audio {
constructor() {
super();
this._lyrics = '';
Expand All @@ -181,7 +182,7 @@ class myAudio extends Audio {
}
}

var player = new myAudio();
var player = new MyAudio();
player.controls = true;
player.lyrics = 'Never gonna give you up';
document.querySelector('body').appendChild(player);
Expand Down
7 changes: 4 additions & 3 deletions collections-iterators-es6/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ for (var i = 0; i < 5; i++) {
}

ChromeSamples.log(randomIntegers.size, 'distinct integers were generated.');
ChromeSamples.log('The number 10 was', randomIntegers.has(10) ? '' : 'not', 'one of them.');
ChromeSamples.log('The number 10 was',
randomIntegers.has(10) ? '' : 'not', 'one of them.');
ChromeSamples.log('Here\'s all of them:');

// Use for...of to iterate over the items in the Set.
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-iteration-statements
// The Set iterator yields a single value corresponding to each entry in the Set.
for (var item of randomIntegers) {
ChromeSamples.log(item);
for (var integer of randomIntegers) {
ChromeSamples.log(integer);
}

ChromeSamples.log('\nCreating and iterating over a Map:');
Expand Down
12 changes: 10 additions & 2 deletions css-motion-path/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ var positionTiming = {duration: 12000, iterations: Infinity};
firstScissorHalf.animate(positionKeyframes, positionTiming);
secondScissorHalf.animate(positionKeyframes, positionTiming);

var firstRotationKeyframes = [{motionRotation: 'auto 0deg'}, {motionRotation: 'auto -45deg'}, {motionRotation: 'auto 0deg'}];
var secondRotationKeyframes = [{motionRotation: 'auto 0deg'}, {motionRotation: 'auto 45deg'}, {motionRotation: 'auto 0deg'}];
var firstRotationKeyframes = [
{motionRotation: 'auto 0deg'},
{motionRotation: 'auto -45deg'},
{motionRotation: 'auto 0deg'}
];
var secondRotationKeyframes = [
{motionRotation: 'auto 0deg'},
{motionRotation: 'auto 45deg'},
{motionRotation: 'auto 0deg'}
];
var rotationTiming = {duration: 1000, iterations: Infinity};
firstScissorHalf.animate(firstRotationKeyframes, rotationTiming);
secondScissorHalf.animate(secondRotationKeyframes, rotationTiming);
15 changes: 6 additions & 9 deletions cut-and-copy/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ function performCopyEmail() {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
ChromeSamples.log('Copy email command was ' + msg);
} catch(err) {
} catch (err) {
ChromeSamples.log('execCommand Error', err);
}
window.getSelection().removeAllRanges();
}

function performCutTextarea() {
var hasSelection = document.queryCommandEnabled('cut');
var cutTextarea = document.querySelector('.js-cuttextarea');
cutTextarea.select();

try {
var successful = document.execCommand('cut');
var msg = successful ? 'successful' : 'unsuccessful';
ChromeSamples.log('Cutting text command was ' + msg);
} catch(err) {
} catch (err) {
ChromeSamples.log('execCommand Error', err);
}
}
Expand All @@ -37,12 +36,10 @@ var copyEmailBtn = document.querySelector('.js-emailcopybtn');
copyEmailBtn.addEventListener('click', performCopyEmail);
cutTextareaBtn.addEventListener('click', performCutTextarea);

// TODO: The initial state should be disabled
// then enable based on queryCommandSupported
// This is currently a bug: crbug.com/476508

// The initial state should be disabled, and then enable based on
// queryCommandSupported. This is currently a bug: crbug.com/476508
// Set the initial state
/**
/*
cutTextareaBtn.disabled = !document.queryCommandSupported('cut');
copyEmailBtn.disabled = !document.queryCommandSupported('copy');
**/
*/
4 changes: 2 additions & 2 deletions encoding-api/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ function fetchAndDecode(file, encoding) {
// rather than letting XMLHttpRequest decode the data first.
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
if (this.status == 200) {
if (this.status === 200) {
// The decode() method takes a DataView as a parameter, which is a wrapper on top of the ArrayBuffer.
var dataView = new DataView(this.response);
// The TextDecoder interface is documented at http://encoding.spec.whatwg.org/#interface-textdecoder
var decoder = new TextDecoder(encoding);
var decodedString = decoder.decode(dataView);
ChromeSamples.log(decodedString);
} else {
ChromeSample.setStatus('Error while requesting', file, this.status);
ChromeSamples.setStatus('Error while requesting', file, this.status);
}
};
xhr.send();
Expand Down
2 changes: 1 addition & 1 deletion event-istrusted/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ greenButton.addEventListener('click', function(event) {
}
});

redButton.addEventListener('click', function(event) {
redButton.addEventListener('click', function() {
greenButton.click();
});
11 changes: 7 additions & 4 deletions extended-object-literals-es6/demo.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

var a = 'somestring', b = 5, c = {'key': 'value'};
var a = 'somestring';
var b = 5;
var c = {key: 'value'};

// The following two declarations are equivalent:
var es5 = {a: a, b: b, c: c};
var es6 = {a, b, c}; // Property name is inferred from variable name
ChromeSamples.log('es5:', es5);
ChromeSamples.log('es6:', es6);

function person(name, age){
function person(name, age) {
return {name, age}; // Again, property name is inferred
}

Expand All @@ -20,8 +22,9 @@ var tools = {
return i + 1;
},
* countdown(i) { // also works with generators
while(i>0)
while (i > 0) {
yield i--;
},
}
}
};
ChromeSamples.log('If you add1() to 5 you get', tools.add1(5));
Loading

0 comments on commit 5c20f8d

Please sign in to comment.