Skip to content

Commit b08f5e0

Browse files
authored
feat: Add general type-aware linting (#1497)
* Support type-aware linting by environment variable * `ENDO_LINT_TYPES=SRC`: Limit to "src" directories (increases time ~50%). * `ENDO_LINT_TYPES=FULL`: Include all files (increases time **greatly**).
2 parents 149c82d + b4cc976 commit b08f5e0

Some content is hidden

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

71 files changed

+738
-210
lines changed

jsconfig.eslint-base.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"checkJs": false,
6+
"noEmit": true,
7+
"downlevelIteration": true,
8+
"strictNullChecks": true,
9+
"moduleResolution": "node"
10+
},
11+
"include": [],
12+
"exclude": ["packages/test262-runner/test262"]
13+
}

jsconfig.eslint-full.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./jsconfig.eslint-base.json",
3+
"include": [
4+
"**/*.js",
5+
"**/*.ts"
6+
]
7+
}

jsconfig.eslint-src.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./jsconfig.eslint-base.json",
3+
"include": [
4+
"*.js",
5+
"*.ts",
6+
"packages/*/*.js",
7+
"packages/*/*.ts",
8+
"packages/*/src/**/*.js",
9+
"packages/*/src/**/*.ts"
10+
]
11+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"devDependencies": {
1212
"@octokit/core": "^3.4.0",
13+
"@typescript-eslint/eslint-plugin": "^5.53.0",
1314
"ava": "^5.2.0",
1415
"eslint": "^7.32.0",
1516
"eslint-config-airbnb-base": "^14.0.0",
@@ -20,7 +21,7 @@
2021
"eslint-plugin-prettier": "^3.4.1",
2122
"lerna": "^5.6.2",
2223
"lerna-update-wizard": "^0.17.5",
23-
"typescript": "~4.9.4"
24+
"typescript": "~4.9.5"
2425
},
2526
"scripts": {
2627
"clean": "lerna clean",
@@ -37,7 +38,7 @@
3738
"build": "lerna run build"
3839
},
3940
"dependencies": {
40-
"@typescript-eslint/parser": "^5.27.0",
41+
"@typescript-eslint/parser": "^5.53.0",
4142
"conventional-changelog-conventionalcommits": "^4.6.0",
4243
"patch-package": "^6.2.2"
4344
}

packages/base64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"eslint-plugin-import": "^2.27.5",
5151
"eslint-plugin-prettier": "^3.4.1",
5252
"prettier": "^2.8.0",
53-
"typescript": "~4.9.4"
53+
"typescript": "~4.9.5"
5454
},
5555
"files": [
5656
"LICENSE*",

packages/bundle-source/src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ const textEncoder = new TextEncoder();
3232
const textDecoder = new TextDecoder();
3333
const readPowers = makeReadPowers({ fs, url, crypto });
3434

35-
// Find the longest common prefix of an array of strings.
35+
/**
36+
* Finds the longest common prefix in an array of strings.
37+
*
38+
* @param {string[]} strings
39+
* @returns {string}
40+
*/
3641
function longestCommonPrefix(strings) {
3742
if (strings.length === 0) {
3843
return '';
@@ -255,6 +260,10 @@ async function bundleNestedEvaluateAndGetExports(
255260
throw Error('No entrypoint found in output bundle');
256261
}
257262

263+
/**
264+
* @param {string} a
265+
* @param {string} b
266+
*/
258267
const strcmp = (a, b) => {
259268
if (a < b) {
260269
return -1;

packages/bundle-source/src/tool.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const { details: X, quote: q } = assert;
1010
const USAGE =
1111
'bundle-source [--cache-js | --cache-json] cache/ module1.js bundleName1 module2.js bundleName2 ...';
1212

13+
/**
14+
* @typedef {object} BundleMeta
15+
* @property {string} bundleFileName
16+
* @property {string} bundleTime ISO format
17+
* @property {{ relative: string, absolute: string }} moduleSource
18+
* @property {Array<{ relativePath: string, mtime: string }>} contents
19+
*/
20+
1321
export const makeFileReader = (fileName, { fs, path }) => {
1422
const make = there => makeFileReader(there, { fs, path });
1523
return harden({
@@ -68,6 +76,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
6876
try {
6977
const itemRd = cwd.neighbor(new URL(loc).pathname);
7078
const ref = srcRd.relative(itemRd.absolute());
79+
/** @type {import('fs').Stats} */
7180
const { mtime } = await itemRd.stat();
7281
modTimeByPath.set(ref, mtime);
7382
// console.log({ loc, mtime, ref });
@@ -91,8 +100,10 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
91100
const bundleFileName = toBundleName(targetName);
92101
const bundleWr = wr.neighbor(bundleFileName);
93102
await bundleWr.writeText(code);
103+
/** @type {import('fs').Stats} */
94104
const { mtime: bundleTime } = await bundleWr.readOnly().stat();
95105

106+
/** @type {BundleMeta} */
96107
const meta = {
97108
bundleFileName,
98109
bundleTime: bundleTime.toISOString(),
@@ -122,6 +133,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
122133
X`${q(targetName)}: cannot read bundle metadata: ${q(ioErr)}`,
123134
);
124135
}
136+
/** @type {BundleMeta} */
125137
const meta = JSON.parse(txt);
126138
const {
127139
bundleFileName,
@@ -130,6 +142,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
130142
moduleSource: { absolute: moduleSource },
131143
} = meta;
132144
assert.equal(bundleFileName, toBundleName(targetName));
145+
/** @type {import('fs').Stats} */
133146
const { mtime: actualBundleTime } = await wr
134147
.readOnly()
135148
.neighbor(bundleFileName)
@@ -139,6 +152,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
139152
const actualTimes = await Promise.all(
140153
contents.map(async ({ relativePath }) => {
141154
const itemRd = moduleRd.neighbor(relativePath);
155+
/** @type {import('fs').Stats} */
142156
const { mtime } = await itemRd.stat();
143157
return { relativePath, mtime: mtime.toISOString() };
144158
}),
@@ -195,6 +209,11 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => {
195209
});
196210
};
197211

212+
/**
213+
* @param {[string, string, string[]]} args
214+
* @param {*} powers
215+
* @returns {void}
216+
*/
198217
export const main = async (args, { fs, url, crypto, path }) => {
199218
const [to, dest, ...pairs] = args;
200219
if (!(dest && pairs.length > 0 && pairs.length % 2 === 0)) {

packages/check-bundle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"eslint-plugin-import": "^2.27.5",
5656
"eslint-plugin-prettier": "^3.4.1",
5757
"prettier": "^2.8.0",
58-
"typescript": "~4.9.4"
58+
"typescript": "~4.9.5"
5959
},
6060
"files": [
6161
"*.js",

packages/cjs-module-analyzer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"eslint-plugin-import": "^2.27.5",
4141
"eslint-plugin-prettier": "^3.4.1",
4242
"prettier": "^2.8.0",
43-
"typescript": "~4.9.4"
43+
"typescript": "~4.9.5"
4444
},
4545
"files": [
4646
"LICENSE*",

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"eslint-plugin-import": "^2.27.5",
4646
"eslint-plugin-prettier": "^3.4.1",
4747
"prettier": "^2.8.0",
48-
"typescript": "~4.9.4"
48+
"typescript": "~4.9.5"
4949
},
5050
"files": [
5151
"LICENSE*",

0 commit comments

Comments
 (0)