Skip to content

Commit bcdcc75

Browse files
feat(typescript): add type linting and configure gts as lint command (GoogleChrome#18)
1 parent ffe1680 commit bcdcc75

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
"eleventy": "npx eleventy",
1010
"gulp:watch": "npx gulp watch",
1111
"gulp": "npx gulp",
12+
"lint:js": "gts check",
13+
"lint:types": "tsc --noEmit",
14+
"lint": "npm-run-all lint:js lint:types",
1215
"production": "NODE_ENV=production npm-run-all clean gulp rollup eleventy",
1316
"rollup": "npx rollup -c",
1417
"rollup:watch": "npx chokidar \"site/**/*.js\" -c \"npx rollup -c\"",
1518
"server": "node ./server",
16-
"check": "gts check",
1719
"fix": "gts fix"
1820
},
1921
"license": "Apache 2.0",

site/_data/lib/links.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
*
77
* @param {string} itemUrl The link in question
88
* @param {string} pageUrl The page context
9-
* @returns {string} The attributes or empty
9+
* @returns {string|undefined} The attributes or empty
1010
*/
1111
function getLinkActiveState(itemUrl, pageUrl) {
1212
if (itemUrl === pageUrl) {
1313
return ' data-state="active" aria-current="page"';
14-
}
15-
16-
if (itemUrl.length > 1 && pageUrl.indexOf(itemUrl) === 0) {
14+
} else if (itemUrl.length > 1 && pageUrl.indexOf(itemUrl) === 0) {
1715
return ' data-state="active"';
1816
}
17+
return;
1918
}
2019

2120
module.exports = {

tsconfig.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"allowJs": true,
6+
"checkJs": true,
7+
"moduleResolution": "node",
8+
"resolveJsonModule": true,
9+
"outDir": "dist",
10+
"rootDir": "./",
11+
"noEmit": true,
12+
"strict": true,
13+
"noImplicitAny": false,
14+
"strictNullChecks": true,
15+
"strictFunctionTypes": true,
16+
"noUnusedLocals": true,
17+
"noUnusedParameters": true,
18+
"noImplicitReturns": true,
19+
"noFallthroughCasesInSwitch": true,
20+
"baseUrl": "./",
21+
"typeRoots": [
22+
"node_modules/@types",
23+
],
24+
"allowSyntheticDefaultImports": true,
25+
"esModuleInterop": true,
26+
"skipLibCheck": true,
27+
"forceConsistentCasingInFileNames": true
28+
},
29+
"include": [
30+
"site/**/*",
31+
"types/**/*.d.ts"
32+
],
33+
"exclude": [
34+
".github",
35+
".vscode",
36+
"dist",
37+
"node_modules",
38+
"test",
39+
"./*.js"
40+
]
41+
}

types/todo.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
declare global {
18+
export type TODO = any; // eslint-disable-line
19+
}
20+
21+
// empty export to keep file a module
22+
export {};

0 commit comments

Comments
 (0)