Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #67 from gauntface/google-eslint
Browse files Browse the repository at this point in the history
Switching over to google linting rules
  • Loading branch information
jeffposnick committed Dec 9, 2015
2 parents ae31aae + df31be1 commit 23f66ef
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
demo/dist/
demo/app/service-worker.js
app-shell-demo/
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"extends": "xo",
"extends": "google",
"rules": {
"default-case": 0,
"indent": [2, 2, {"SwitchCase": 1}],
"no-console": 0,
"no-inline-comments": 0,
"space-before-function-paren": [2, "never"]
"space-before-function-paren": [2, "never"],
"require-jsdoc": 0
}
}
1 change: 1 addition & 0 deletions app-shell-demo/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/components/
4 changes: 2 additions & 2 deletions app-shell-demo/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "xo",
"plugins": [
"react"
],
Expand All @@ -11,6 +10,7 @@
"react/jsx-uses-vars": 1,
"indent": [2, 2, {"SwitchCase": 1}],
"space-before-function-paren": 0,
"default-case": 0
"default-case": 0,
"require-jsdoc": 0
}
}
8 changes: 6 additions & 2 deletions app-shell-demo/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ gulp.task('generate-service-worker', () => {

gulp.task('build', callback => {
sequence(
['bundle-app', 'bundle-third-party', 'copy-static', 'copy-third-party-sw', 'sass'],
[
'bundle-app', 'bundle-third-party', 'copy-static',
'copy-third-party-sw', 'sass', 'lint'
],
'uglify-js',
'version-assets',
'generate-service-worker',
Expand Down Expand Up @@ -177,7 +180,8 @@ gulp.task('lint', () => {
});

gulp.task('watch', () => {
gulp.watch(`${SRC_DIR}/**/*.{js,jsx}`, sequence('bundle-app', 'lint', 'version-assets'));
gulp.watch(`${SRC_DIR}/**/*.{js,jsx}`, sequence('bundle-app',
'lint', 'version-assets'));
gulp.watch(`${SRC_DIR}/static/**/*`, ['copy-static']);
gulp.watch(`${SRC_DIR}/static/sass/*.scss`, ['sass']);
});
Expand Down
7 changes: 5 additions & 2 deletions app-shell-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"browserify": "^11.2.0",
"compression": "^1.6.0",
"del": "^2.0.2",
"eslint": "^1.6.0",
"eslint-config-xo": "^0.6.0",
"eslint": "^1.10.3",
"eslint-config-google": "^0.3.0",
"eslint-plugin-react": "^3.5.1",
"express": "^4.13.3",
"express-handlebars": "^2.0.1",
Expand Down Expand Up @@ -49,5 +49,8 @@
"scripts": {
"postinstall": "gulp build",
"start": "node index.js"
},
"eslintConfig": {
"extends": "google"
}
}
3 changes: 2 additions & 1 deletion app-shell-demo/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {default as Immutable, fromJS} from 'immutable';

let reducer = handleActions({
LOAD_URL: (state, action) => ({
urlToResponse: state.urlToResponse.set(action.payload.url, fromJS(action.payload.json))
urlToResponse: state.urlToResponse.set(action.payload.url,
fromJS(action.payload.json))
})
}, {urlToResponse: new Immutable.Map()});

Expand Down
9 changes: 6 additions & 3 deletions app-shell-demo/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ app.engine('handlebars', expressHandlebars());
app.set('view engine', 'handlebars');
app.set('views', path.join(__dirname, 'views'));

let revManifest = JSON.parse(fs.readFileSync(path.join('build', 'rev-manifest.json'), 'utf8'));
let revManifest = JSON.parse(
fs.readFileSync(path.join('build', 'rev-manifest.json'), 'utf8'));
let styles = new Map(
Object.keys(revManifest).filter(originalFile => originalFile.endsWith('.css'))
.map(originalFile => {
let revFile = revManifest[originalFile];
let contents = fs.readFileSync(path.join('build', 'rev', revFile), 'utf8');
let contents = fs.readFileSync(
path.join('build', 'rev', revFile), 'utf8');
return [originalFile, contents];
})
);

app.use((req, res) => {
let location = createMemoryHistory().createLocation(req.url);
let createStoreWithMiddleware = applyMiddleware(promiseMiddleware)(createStore);
let createStoreWithMiddleware = applyMiddleware(
promiseMiddleware)(createStore);
let store = createStoreWithMiddleware(reducer);

match({routes, location}, (error, redirectLocation, renderProps) => {
Expand Down
3 changes: 2 additions & 1 deletion app-shell-demo/src/static/js/register-service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
'use strict';

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
navigator.serviceWorker.register('/service-worker.js')
.then(function(registration) {
registration.onupdatefound = function() {
var installingWorker = registration.installing;
installingWorker.onstatechange = function() {
Expand Down
15 changes: 10 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ function setDefaults(cli) {
cli.flags.stripPrefix = cli.flags.stripPrefix || cli.flags.root;
cli.flags.swFile = cli.flags.swFile || 'service-worker.js';
cli.flags.swFilePath = path.join(cli.flags.root, cli.flags.swFile);
cli.flags.staticFileGlobs = cli.flags.staticFileGlobs ? [cli.flags.staticFileGlobs] : [cli.flags.root + '/**/*.*'];
cli.flags.staticFileGlobs = cli.flags.staticFileGlobs ?
[cli.flags.staticFileGlobs] : [cli.flags.root + '/**/*.*'];
cli.flags.cacheId = cli.flags.cacheId || cli.pkg.name;
if (cli.flags.ignoreUrlParametersMatching) {
cli.flags.ignoreUrlParametersMatching = cli.flags.ignoreUrlParametersMatching.split(',').map(function(s) {
return new RegExp(s);
});
cli.flags.ignoreUrlParametersMatching =
cli.flags.ignoreUrlParametersMatching.split(',').map(
function(s) {
return new RegExp(s);
}
);
}
if (cli.flags.importScripts) {
cli.flags.importScripts = cli.flags.importScripts.split(',');
Expand All @@ -54,5 +58,6 @@ swPrecache.write(options.swFilePath, options, function(error) {
throw error;
}

console.log(options.swFilePath, 'has been generated with the service worker contents.');
console.log(options.swFilePath,
'has been generated with the service worker contents.');
});
3 changes: 2 additions & 1 deletion demo/app/js/service-worker-registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ if ('serviceWorker' in navigator) {
// It won't be able to control pages unless it's located at the same level or higher than them.
// *Don't* register service worker file in, e.g., a scripts/ sub-directory!
// See https://github.com/slightlyoff/ServiceWorker/issues/468
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
navigator.serviceWorker.register('service-worker.js')
.then(function(registration) {
// Check to see if there's an updated version of service-worker.js with new files to cache:
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-registration-update-method
if (typeof registration.update === 'function') {
Expand Down
7 changes: 4 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ var spawn = require('child_process').spawn;
gulp.task('default', ['test', 'lint']);

gulp.task('generate-demo-service-worker', function(callback) {
spawn('gulp', ['--cwd', 'demo', 'generate-service-worker-dev'], {stdio: 'inherit'})
.on('close', callback);
spawn('gulp', ['--cwd', 'demo', 'generate-service-worker-dev'],
{stdio: 'inherit'})
.on('close', callback);
});

gulp.task('lint', ['generate-demo-service-worker'], function() {
return gulp.src(['{lib,test,demo}/**/*.js', '*.js'])
return gulp.src(['./**/*.js'])
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
Expand Down
6 changes: 4 additions & 2 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
var URL = require('dom-urls');

module.exports = {
stripIgnoredUrlParameters: function(originalUrl, ignoreUrlParametersMatching) {
stripIgnoredUrlParameters: function(originalUrl,
ignoreUrlParametersMatching) {
var url = new URL(originalUrl);

url.search = url.search.slice(1) // Exclude initial '?'
Expand All @@ -41,7 +42,8 @@ module.exports = {
return url.toString();
},

populateCurrentCacheNames: function(precacheConfig, cacheNamePrefix, baseUrl) {
populateCurrentCacheNames: function(precacheConfig,
cacheNamePrefix, baseUrl) {
var absoluteUrlToCacheName = {};
var currentCacheNamesToAbsoluteUrl = {};

Expand Down
32 changes: 21 additions & 11 deletions lib/sw-precache.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function getHash(data) {
return md5.digest('hex');
}

// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
Expand Down Expand Up @@ -95,25 +94,30 @@ function generate(params, callback) {
var cumulativeSize = 0;

params.staticFileGlobs.forEach(function(globPattern) {
var filesAndSizesAndHashes = getFilesAndSizesAndHashesForGlobPattern(globPattern);
var filesAndSizesAndHashes =
getFilesAndSizesAndHashesForGlobPattern(globPattern);

// The files returned from glob are sorted by default, so we don't need to sort here.
filesAndSizesAndHashes.forEach(function(fileAndSizeAndHash) {
if (fileAndSizeAndHash.size <= params.maximumFileSizeToCacheInBytes) {
// Strip the prefix to turn this into a relative URL.
var relativeUrl = fileAndSizeAndHash.file
.replace(new RegExp('^' + escapeRegExp(params.stripPrefix)), params.replacePrefix)
.replace(
new RegExp('^' + escapeRegExp(params.stripPrefix)),
params.replacePrefix)
.replace(path.sep, '/');
relativeUrlToHash[relativeUrl] = fileAndSizeAndHash.hash;

if (params.verbose) {
params.logger(util.format('Caching static resource "%s" (%s)', fileAndSizeAndHash.file,
params.logger(util.format('Caching static resource "%s" (%s)',
fileAndSizeAndHash.file,
prettyBytes(fileAndSizeAndHash.size)));
}

cumulativeSize += fileAndSizeAndHash.size;
} else {
params.logger(util.format('Skipping static resource "%s" (%s) - max size is %s',
params.logger(
util.format('Skipping static resource "%s" (%s) - max size is %s',
fileAndSizeAndHash.file, prettyBytes(fileAndSizeAndHash.size),
prettyBytes(params.maximumFileSizeToCacheInBytes)));
}
Expand All @@ -123,7 +127,9 @@ function generate(params, callback) {
Object.keys(params.dynamicUrlToDependencies).forEach(function(dynamicUrl) {
if (!Array.isArray(params.dynamicUrlToDependencies[dynamicUrl])) {
throw Error(util.format(
'The value for the dynamicUrlToDependencies.%s option must be an Array.', dynamicUrl));
'The value for the dynamicUrlToDependencies.%s ' +
'option must be an Array.',
dynamicUrl));
}

var filesAndSizesAndHashes = params.dynamicUrlToDependencies[dynamicUrl]
Expand All @@ -135,8 +141,9 @@ function generate(params, callback) {
// Provide some additional information about the failure if the file is missing.
if (e.code === 'ENOENT') {
params.logger(util.format(
'%s was listed as a dependency for dynamic URL %s, but the file does not exist. ' +
'Either remove the entry as a dependency, or correct the path to the file.',
'%s was listed as a dependency for dynamic URL %s, but ' +
'the file does not exist. Either remove the entry as a ' +
'dependency, or correct the path to the file.',
file, dynamicUrl
));
}
Expand All @@ -156,7 +163,8 @@ function generate(params, callback) {
relativeUrlToHash[dynamicUrl] = getHash(concatenatedHashes);

if (params.verbose) {
params.logger(util.format('Caching dynamic URL "%s" with dependencies on %j',
params.logger(util.format(
'Caching dynamic URL "%s" with dependencies on %j',
dynamicUrl, params.dynamicUrlToDependencies[dynamicUrl]));
}
});
Expand All @@ -173,7 +181,8 @@ function generate(params, callback) {
return [relativeUrl, relativeUrlToHash[relativeUrl]];
});

params.logger(util.format('Total precache size is about %s for %d resources.',
params.logger(util.format(
'Total precache size is about %s for %d resources.',
prettyBytes(cumulativeSize), relativeUrls.length));

fs.readFile(params.templateFilePath, 'utf8', function(error, data) {
Expand All @@ -192,7 +201,8 @@ function generate(params, callback) {
externalFunctions: externalFunctions,
handleFetch: params.handleFetch,
ignoreUrlParametersMatching: params.ignoreUrlParametersMatching,
importScripts: params.importScripts ? params.importScripts.map(JSON.stringify).join(',') : null,
importScripts: params.importScripts ?
params.importScripts.map(JSON.stringify).join(',') : null,
// Ensure that anything false is translated into '', since this will be treated as a string.
navigateFallback: params.navigateFallback || '',
precacheConfig: JSON.stringify(precacheConfig),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"devDependencies": {
"del": "^1.2.0",
"eslint": "^1.9.0",
"eslint-config-xo": "^0.6.0",
"eslint": "^1.10.3",
"eslint-config-google": "^0.3.0",
"express": "^4.12.4",
"gh-pages": "^0.3.1",
"grunt": "^0.4.5",
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

// This is a test and we want descriptions to be useful, if this
// breaks the max-length, it's ok.

/* eslint-disable max-len */
/* eslint-env node, mocha */
'use strict';

Expand Down

0 comments on commit 23f66ef

Please sign in to comment.