Skip to content

Commit

Permalink
add task for simple auto fix
Browse files Browse the repository at this point in the history
can fix:
semi
eqeqeq
quotes
  • Loading branch information
erwinmombay committed Oct 28, 2015
1 parent 540b7ac commit b7b6f64
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 68 deletions.
45 changes: 27 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,43 @@
"browser": true
},
"rules": {
"semi": 2,
"google-camelcase/google-camelcase": 2,
"no-eval": 2,
"array-bracket-spacing": [2, "never"],
"arrow-parens": [2, "as-needed"],
"curly": 2,
"radix": 2,
"dot-location": [2, "property"],
"eol-last": 2,
"no-debugger": 2,
"google-camelcase/google-camelcase": 2,
"key-spacing": 2,
"max-len": [2, 80, 4, { "ignoreComments": true, "ignoreUrls": true, "ignorePattern": "" }],
"no-alert": 2,
"no-debugger": 2,
"no-div-regex": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implicit-coercion": [2, { "boolean": false }],
"no-implied-eval": 2,
"no-native-reassign": 2,
"no-lone-blocks": 2,
"no-sequences": 2,
"no-throw-literal": 2,
"no-warning-comments": [2, { "terms": ["do not submit"], "location": "anywhere" }],
"wrap-iife": [2, "any"],
"no-unused-expressions": 0,
"no-iterator": 2,
"no-lone-blocks": 2,
"no-multi-spaces": 2,
"no-native-reassign": 2,
"no-redeclare": 2,
"no-script-url": 2,
"no-implicit-coercion": [2, { "boolean": false }],
"no-useless-concat": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-spaced-func": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-unused-expressions": 0,
"no-useless-call": 2,
"no-div-regex": 2,
"max-len": [2, 80, 4, { "ignoreComments": true, "ignoreUrls": true, "ignorePattern": "" }],
"dot-location": [2, "property"],
"arrow-parens": [2, "as-needed"]
"no-useless-concat": 2,
"no-warning-comments": [2, { "terms": ["do not submit"], "location": "anywhere" }],
"radix": 2,
"semi": 2,
"space-after-keywords": 2,
"space-before-function-paren": [2, "never"],
"space-in-parens": 2,
"space-infix-ops": 2,
"wrap-iife": [2, "any"]
}
}
1 change: 1 addition & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ If you have any questions, feel free to ask on the issue or join us on [Slack](h
| `gulp dist` | Builds production binaries. |
| `gulp lint` | Validates against Google Closure Linter. |
| `gulp lint --watch` | Watches for changes in files, Validates against Google Closure Linter.|
| `gulp lint-fix` | Fixes simple lint warnings/errors automatically. |
| `gulp build` | Builds the AMP library. |
| `gulp clean` | Removes build output. |
| `gulp css` | Recompile css to build directory. |
Expand Down
7 changes: 4 additions & 3 deletions build-system/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ var karma = {
module.exports = {
testPaths: testPaths,
karma: karma,
src: {
exclude: '!{node_modules,build,dist,dist.3p}/**/*.*',
},
lintGlobs: [
'**/*.js',
'!{node_modules,build,dist,dist.3p,third_party,build-system}/**/*.*'
],
presubmitGlobs: [
'**/*.{css,js,html,md}',
// This does match dist.3p/current, so we run presubmit checks on the
Expand Down
20 changes: 16 additions & 4 deletions build-system/tasks/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
var argv = require('minimist')(process.argv.slice(2));
var config = require('../config');
var eslint = require('gulp-eslint');
var exec = require('child_process').exec;
var gulp = require('gulp-help')(require('gulp'));
var lazypipe = require('lazypipe');
var util = require('gulp-util');
Expand All @@ -26,6 +27,7 @@ var watch = require('gulp-watch');
var isWatching = (argv.watch || argv.w) || false;

var options = {
fix: false,
plugins: ['eslint-plugin-google-camelcase'],
"ecmaFeatures": {
"modules": true,
Expand All @@ -36,17 +38,15 @@ var options = {
},
};

var srcs = ['**/*.js', config.src.exclude];

var watcher = lazypipe().pipe(watch, srcs);
var watcher = lazypipe().pipe(watch, config.lintGlobs);

/**
* Run the eslinter on the src javascript and log the output
* @return {!Stream} Readable stream
*/
function lint() {
var errorsFound = false;
var stream = gulp.src(srcs);
var stream = gulp.src(config.lintGlobs);

if (isWatching) {
stream = stream.pipe(watcher());
Expand All @@ -59,14 +59,26 @@ function lint() {
}))
.on('end', function() {
if (errorsFound) {
util.log(util.colors.blue('Run `gulp lint-fix` to automatically ' +
'fix some of these lint warnings/errors. This is a destructive ' +
'operation (operates on the file system) so please make sure ' +
'you commit before running.'));
process.exit(1);
}
});
}

function lintFix() {
// Temporary until we figure out gulp-eslint fix and destination write.
exec('node_modules/eslint/bin/eslint.js ' +
'{src,3p,ads,builtins,extensions,testing,test}/**/*.js ' +
'-c .eslintrc --fix --plugin google-camelcase');
}

gulp.task('lint', 'Validates against Google Closure Linter', lint,
{
options: {
'watch': 'Watches for changes in files, validates against the linter'
}
});
gulp.task('lint-fix', 'Auto fixes some simple lint errors', lintFix);
2 changes: 1 addition & 1 deletion extensions/amp-audio/0.1/amp-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Layout, getLengthNumeral} from '../../../src/layout';
import {Layout, getLengthNumeral} from '../../../src/layout';
import {assertHttpsUrl} from '../../../src/url';
import {loadPromise} from '../../../src/event-helper';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-image-lightbox/0.1/amp-image-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export class ImageViewer {
return;
}

let newScale = this.startScale_ * (1 + zoomSign * dist / 100);
let newScale = this.startScale_ * (1 + zoomSign * dist / 100);
let deltaCenterX = this.viewerBox_.width / 2 - centerClientX;
let deltaCenterY = this.viewerBox_.height / 2 - centerClientY;
deltaX = Math.min(deltaCenterX, deltaCenterX * (dist / 100));
Expand Down
48 changes: 24 additions & 24 deletions extensions/amp-pinterest/0.1/amp-pinterest.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AmpPinterest extends AMP.BaseElement {
}

// open a new window
let pop = function (url, shouldPop) {
let pop = function(url, shouldPop) {
if (shouldPop) {
// amp=1&guid=guid are already in the query before long fields
window.open(url, '_pinit', POP);
Expand All @@ -90,7 +90,7 @@ class AmpPinterest extends AMP.BaseElement {
};

// log a string
let log = function (str) {
let log = function(str) {
let call = new Image();
let query = 'https://log.pinterest.com/?guid=' + guid;
query = query + '&amp=1';
Expand Down Expand Up @@ -127,7 +127,7 @@ class AmpPinterest extends AMP.BaseElement {
};

// set a DOM property or text attribute
let set = function (el, att, string) {
let set = function(el, att, string) {
if (typeof el[att] === 'string') {
el[att] = string;
} else {
Expand All @@ -136,7 +136,7 @@ class AmpPinterest extends AMP.BaseElement {
};

// create a DOM element
let make = function (obj) {
let make = function(obj) {
let el = false, tag, att;
for (tag in obj) {
el = document.createElement(tag);
Expand All @@ -151,7 +151,7 @@ class AmpPinterest extends AMP.BaseElement {
};

// filter tags from API input
let filter = function (str) {
let filter = function(str) {
let decoded, ret;
decoded = '';
ret = '';
Expand All @@ -166,7 +166,7 @@ class AmpPinterest extends AMP.BaseElement {
// save our outside context so we can return properly after rendering
let that = this;

let makePin = function () {
let makePin = function() {

// make an embedded pin widget
// pinId will be inferred from pinUrl
Expand All @@ -181,9 +181,9 @@ class AmpPinterest extends AMP.BaseElement {

let width = that.element.getAttribute('data-width');

let structure = make({'span':{}});
let structure = make({'span': {}});

let renderPin = function (r) {
let renderPin = function(r) {

if (r && r.data && r.data[0] && !r.data[0].error) {
let p = r.data[0];
Expand All @@ -203,12 +203,12 @@ class AmpPinterest extends AMP.BaseElement {

structure.className = className;

let container = make({'span':{
let container = make({'span': {
'className': '-amp-pinterest-embed-pin-inner',
'data-pin-log': 'embed_pin'
}});

let img = make({'img':{
let img = make({'img': {
'src': imgUrl,
'className': '-amp-pinterest-embed-pin-image',
'data-pin-no-hover': true,
Expand All @@ -235,7 +235,7 @@ class AmpPinterest extends AMP.BaseElement {

// description
if (p.description) {
let description = make({'span':{
let description = make({'span': {
'className': '-amp-pinterest-embed-pin-text-block ' +
'-amp-pinterest-embed-pin-description',
'textContent': filter(p.description)
Expand All @@ -245,18 +245,18 @@ class AmpPinterest extends AMP.BaseElement {

// attribution
if (p.attribution) {
let attribution = make({'span':{
let attribution = make({'span': {
'className': '-amp-pinterest-embed-pin-text-block' +
' -amp-pinterest-embed-pin-attribution'
}});
attribution.appendChild(make({'img':{
attribution.appendChild(make({'img': {
'className': '-amp-pinterest-embed-pin-text-icon-attrib',
'src': p.attribution.provider_icon_url
}}));
attribution.appendChild(make({'span':{
attribution.appendChild(make({'span': {
'textContent': ' by '
}}));
attribution.appendChild(make({'span':{
attribution.appendChild(make({'span': {
'data-pin-href': p.attribution.url,
'textContent': filter(p.attribution.author_name)
}}));
Expand All @@ -265,7 +265,7 @@ class AmpPinterest extends AMP.BaseElement {

// likes and repins
if (p.repin_count || p.like_count) {
let stats = make({'span':{
let stats = make({'span': {
'className': '-amp-pinterest-embed-pin-text-block' +
' -amp-pinterest-embed-pin-stats'
}});
Expand All @@ -290,13 +290,13 @@ class AmpPinterest extends AMP.BaseElement {
// pinner
if (p.pinner) {

let pinner = make({'span':{
let pinner = make({'span': {
'className': '-amp-pinterest-embed-pin-text-block' +
' -amp-pinterest-embed-pin-pinner'
}});

// avatar
pinner.appendChild(make({'img':{
pinner.appendChild(make({'img': {
'className': '-amp-pinterest-embed-pin-pinner-avatar',
'alt': filter(p.pinner.full_name),
'title': filter(p.pinner.full_name),
Expand Down Expand Up @@ -326,7 +326,7 @@ class AmpPinterest extends AMP.BaseElement {


// listen for clicks
structure.addEventListener('click', function (e) {
structure.addEventListener('click', function(e) {
let el = e.target;
let logMe = el.getAttribute('data-pin-log');
if (logMe) {
Expand Down Expand Up @@ -357,7 +357,7 @@ class AmpPinterest extends AMP.BaseElement {
});
};

let makeButton = function () {
let makeButton = function() {

// render a Pin It button
// required: media and description
Expand Down Expand Up @@ -392,15 +392,15 @@ class AmpPinterest extends AMP.BaseElement {
encodeURIComponent(pinDescription);

// start building a link
let a = make({'A':{
let a = make({'A': {
'href': link
}});

// built it
let render = function (r) {
let render = function(r) {

// shorten the pin count so it will fit in our bubble
let prettyPinCount = function (n) {
let prettyPinCount = function(n) {
if (n > 999) {
if (n < 1000000) {
n = parseInt(n / 1000, 10) + 'K+';
Expand Down Expand Up @@ -494,7 +494,7 @@ class AmpPinterest extends AMP.BaseElement {


// listen for clicks
a.addEventListener('click', function (e) {
a.addEventListener('click', function(e) {
log('&type=button_pinit');
pop(this.href, true);
e.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function(config) {
],

preprocessors: {
'test/fixtures/*.html' : ['html2js'],
'test/fixtures/*.html': ['html2js'],
'src/**/*.js': ['browserify'],
'test/**/*.js': ['browserify'],
'extensions/**/test/**/*.js': ['browserify'],
Expand Down
6 changes: 3 additions & 3 deletions src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class AnimationPlayer {
this.segments_[i].func(0, false);
}
}
} catch(e) {
} catch (e) {
log.error(TAG_, 'completion failed: ' + e, e);
success = false;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ class AnimationPlayer {
if (segment.curve && normTime != 1) {
try {
normTime = segment.curve(normLinearTime);
} catch(e) {
} catch (e) {
log.error(TAG_, 'step curve failed: ' + e, e);
this.complete_(/* success */ false, /* dir */ 0);
return;
Expand All @@ -339,7 +339,7 @@ class AnimationPlayer {
}
try {
segment.func(normTime, segment.completed);
} catch(e) {
} catch (e) {
log.error(TAG_, 'step mutate failed: ' + e, e);
this.complete_(/* success */ false, /* dir */ 0);
return;
Expand Down
Loading

0 comments on commit b7b6f64

Please sign in to comment.