Skip to content

Commit 4eb4559

Browse files
refactor(lint:js): use gts for JS linting (GoogleChrome#3130)
* refactor: use `gts` for JS linting * refactor: fix all linted errors * refactor(generate-salt): import `BaseElement` * refactor(web-assessment): test if boolean if `typeof x !== 'boolean'` * fix(BaseStateElement): add `onStateChanged` method * docs(BaseStateElement): add explanation why method exists * refactor: use only single quotes but allow template literals * refactor(generate-salt): recursively call if id exists * refactor: remove spaces in `html` usage * refactor: remove unused component(s) * fix(eslint): allow standard function callbacks in mocha tests * refactor: tweak some more code based on feedback * docs(BaseStateElement): document `onStateChanged` method
1 parent 6f90ef4 commit 4eb4559

File tree

99 files changed

+1619
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1619
-607
lines changed

.eleventy.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const {
8484
serviceWorkerPartials,
8585
} = require(`./${transformsDir}/service-worker-partials`);
8686

87-
module.exports = function(config) {
87+
module.exports = function (config) {
8888
// ----------------------------------------------------------------------------
8989
// PLUGINS
9090
// ----------------------------------------------------------------------------
@@ -104,7 +104,7 @@ module.exports = function(config) {
104104
permalink: true,
105105
permalinkClass: 'w-headline-link',
106106
permalinkSymbol: '#',
107-
slugify: function(str) {
107+
slugify: function (str) {
108108
return slugify(str, {
109109
replacement: '-',
110110
lower: true,
@@ -114,7 +114,7 @@ module.exports = function(config) {
114114
const markdownItAttrsOpts = {
115115
leftDelimiter: '{:',
116116
rightDelimiter: '}',
117-
allowedAttributes: ['id', 'class', /^data\-.*$/],
117+
allowedAttributes: ['id', 'class', /^data-.*$/],
118118
};
119119

120120
const mdLib = markdownIt(markdownItOptions)
@@ -155,10 +155,10 @@ module.exports = function(config) {
155155
config.addCollection('tags', tags);
156156
// Turn collection.all into a lookup table so we can use findBySlug
157157
// to quickly find collection items without looping.
158-
config.addCollection('memoized', function(collection) {
158+
config.addCollection('memoized', (collection) => {
159159
return memoize(collection.getAll());
160160
});
161-
config.addCollection('algolia', function(collection) {
161+
config.addCollection('algolia', (collection) => {
162162
if (process.env.ELEVENTY_ENV === 'prod') {
163163
const algoliaPosts = require(`./${collectionsDir}/algolia-posts`);
164164
return algoliaPosts(collection);

.eslintrc.js

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
module.exports = {
2-
plugins: ['prettier'],
3-
extends: [
4-
'eslint-config-prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier.
5-
'google', // Uses google style guide for js.
6-
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
7-
],
2+
extends: ['./node_modules/gts/.eslintrc.json'],
83
env: {
94
es6: true,
105
node: true,
@@ -18,6 +13,8 @@ module.exports = {
1813
},
1914
globals: {
2015
customElements: true,
16+
firebase: true,
17+
ga: true,
2118
},
2219
rules: {
2320
indent: [
@@ -28,6 +25,36 @@ module.exports = {
2825
},
2926
],
3027
'new-cap': 0,
28+
'no-case-declarations': 0,
29+
'node/no-unpublished-import': 0,
30+
'node/no-unpublished-require': 0,
31+
'node/no-unsupported-features/es-syntax': 0,
32+
'node/no-missing-import': [
33+
'error',
34+
{
35+
allowModules: [
36+
'cache-manifest',
37+
'layout-template',
38+
'webdev_analytics',
39+
'webdev_config',
40+
'webdev_entrypoint',
41+
],
42+
},
43+
],
44+
quotes: [
45+
'warn',
46+
'single',
47+
{avoidEscape: true, allowTemplateLiterals: true},
48+
],
3149
'require-jsdoc': 0,
3250
},
51+
overrides: [
52+
{
53+
files: ['test/**/*.js'],
54+
env: {mocha: true},
55+
rules: {
56+
'prefer-arrow-callback': 0,
57+
},
58+
},
59+
],
3360
};

.prettierrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module.exports = {
2+
...require('gts/.prettierrc.json'),
23
arrowParens: 'always',
3-
bracketSpacing: false,
44
printWidth: 80,
55
semi: true,
6-
singleQuote: true,
76
tabWidth: 2,
87
trailingComma: 'all',
98
};

build.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const buildVirtualJSON = require('./src/build/virtual-json');
3535

3636
process.on('unhandledRejection', (reason, p) => {
3737
log.error('Build had unhandled rejection', reason, p);
38-
process.exit(1);
38+
throw new Error(`Build had unhandled rejection ${reason}`);
3939
});
4040

4141
/**
@@ -50,12 +50,7 @@ const virtualImports = {
5050
webdev_config: {
5151
isProd,
5252
env: process.env.ELEVENTY_ENV || 'dev',
53-
version:
54-
'v' +
55-
new Date()
56-
.toISOString()
57-
.replace(/[\D]/g, '')
58-
.slice(0, 12),
53+
version: 'v' + new Date().toISOString().replace(/[\D]/g, '').slice(0, 12),
5954
firebaseConfig: isProd ? site.firebase.prod : site.firebase.staging,
6055
},
6156
webdev_entrypoint: null,
@@ -351,7 +346,7 @@ async function compressOutput(generated) {
351346
log(`Terser JS output is ${(ratio * 100).toFixed(2)}% of source`);
352347
}
353348

354-
(async function() {
349+
(async function () {
355350
const generatedCount = await build();
356351
log(`Generated ${generatedCount} files`);
357352
if (!isProd) {

compile-css.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const fs = require('fs');
2121
const path = require('path');
2222
const log = require('fancy-log');
2323

24-
const sassEngine = (function() {
24+
const sassEngine = (function () {
2525
try {
2626
// node-sass is faster, but regularly fails to install correctly (native bindings)
2727
return require('node-sass');

gulpfile.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const rename = require('gulp-rename');
2222
const through2 = require('through2');
2323

2424
/* eslint-disable max-len */
25-
const assetTypes = `jpg,jpeg,png,svg,gif,webp,webm,mp4,mov,ogg,wav,mp3,txt,yaml`;
25+
const assetTypes =
26+
'jpg,jpeg,png,svg,gif,webp,webm,mp4,mov,ogg,wav,mp3,txt,yaml';
2627
/* eslint-enable max-len */
2728

2829
const isProd = process.env.ELEVENTY_ENV === 'prod';
@@ -98,7 +99,7 @@ gulp.task('copy-content-assets', () => {
9899

99100
gulp.task('copy-node_modules-assets', () => {
100101
return gulp
101-
.src([`./node_modules/@webcomponents/webcomponentsjs/bundles/*.js`])
102+
.src(['./node_modules/@webcomponents/webcomponentsjs/bundles/*.js'])
102103
.pipe(gulp.dest('./dist/lib/webcomponents/bundles/'));
103104
});
104105

index-algolia.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ const raw = fs.readFileSync('dist/en/algolia.json', 'utf-8');
2525
const indexed = JSON.parse(raw);
2626

2727
// Revision will look like "YYYYMMDDHHMM".
28-
const revision = new Date()
29-
.toISOString()
30-
.substring(0, 16)
31-
.replace(/\D/g, '');
28+
const revision = new Date().toISOString().substring(0, 16).replace(/\D/g, '');
3229
const primaryIndexName = 'webdev';
3330
const deployIndexName = `webdev_deploy_${revision}`;
3431

@@ -59,10 +56,10 @@ async function index() {
5956

6057
// Move our temporary deploy index on-top of the primary index, atomically.
6158
await client.moveIndex(deployIndex.indexName, primaryIndex.indexName);
62-
log(`Done!`);
59+
log('Done!');
6360
}
6461

6562
index().catch((err) => {
6663
log.error(err);
67-
process.exit(1);
64+
throw err;
6865
});

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
module.exports = function(config) {
18+
module.exports = function (config) {
1919
// Test modes:
2020
// quick: single run tests in headless browser.
2121
// dev: watch tests in headless browser.

0 commit comments

Comments
 (0)