Skip to content
Myr

Refactor type-checking setup (#1969)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Refactor type-checking setup * Refactor tsconfig particularly to enable loose check in VSCode, strict checks run separately for type definitions * Simplify includes for tsconfig * Explicitly separate the tsconfig for use with npm run-scripts * Improve comment * Resolved couple of work-in-progress comments * Update tsconfig to recommended node16 lib/module/target * Make checks strict by default and opt-out * Restore broken code to merge later changes * Updates after merge ---------

authored by John Gee · committed by GitHub · parent 744ee3f · Browse files · 12 files+86 added−39 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Wee Bit <aweebit64@gmail.com>

Diff stats

12 files+86 added−39 removed

  • other:+86 added−39 removed

12 files+86 added−39 removed

modified:lib/argument.js-2 removed
modified:lib/command.js-2 removed
8 unmodified lines
9const { Help } = require('./help.js');10const { Option, splitOptionFlags, DualOptions } = require('./option.js');11const { suggestSimilar } = require('./suggestSimilar');1213// @ts-check1413class Command extends EventEmitter {14 /**15 * Initialize a new `Command`.16 *
2163 unmodified lines
modified:lib/error.js-2 removed
modified:lib/help.js-2 removed
6 unmodified lines
7 * @typedef { import("./command.js").Command } Command8 * @typedef { import("./option.js").Option } Option9 */1011// @ts-check1211// Although this is a class, methods are static in style to allow override using subclass or just functions.12class Help {13 constructor() {14 this.helpWidth = undefined;
448 unmodified lines
modified:lib/option.js-2 removed
1const { InvalidArgumentError } = require('./error.js');23// @ts-check43class Option {4 /**5 * Initialize a new `Option` with the given `flags` and `description`.6 *
323 unmodified lines
modified:.eslintrc.js+1 added-1 removed
14 unmodified lines
1516const typescriptSettings = {17 files: ['*.ts', '*.mts'],18 parserOptions: {19 project: './tsconfig.json'19 project: './tsconfig.ts.json'20 },21 plugins: [22 '@typescript-eslint'23 ],
44 unmodified lines
modified:index.js+2 added-6 removed
2 unmodified lines
3const { CommanderError, InvalidArgumentError } = require('./lib/error.js');4const { Help } = require('./lib/help.js');5const { Option } = require('./lib/option.js');67// @ts-check87/**8 * Expose the root command.9 */1013const program = new Command();14exports = module.exports = program; // default export (deprecated)15exports.program = program; // more explicit access to global command1611exports = module.exports = new Command();12exports.program = exports; // More explicit access to global command.13// createArgument, createCommand, and createOption are implicitly available as they are methods on program.1415/**16 * Expose classes
10 unmodified lines
modified:jest.config.js+1 added-1 removed
1const config = {2 testEnvironment: 'node',3 collectCoverage: true,4 transform: {5 '^.+\\.tsx?$': 'ts-jest'5 '^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.ts.json' }]6 },7 testPathIgnorePatterns: [8 '/node_modules/'9 ]
3 unmodified lines
modified:package.json+4 added-4 removed
20 unmodified lines
21 "scripts": {22 "lint": "npm run lint:javascript && npm run lint:typescript",23 "lint:javascript": "eslint index.js esm.mjs \"lib/*.js\" \"tests/**/*.js\"",24 "lint:typescript": "eslint typings/*.ts tests/*.ts",25 "test": "jest && npm run test-typings",25 "test": "jest && npm run typecheck-ts",26 "test-esm": "node ./tests/esm-imports-test.mjs",27 "test-typings": "tsd",28 "typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit",29 "test-all": "npm run test && npm run lint && npm run typescript-checkJS && npm run test-esm"27 "typecheck-ts": "tsd && tsc -p tsconfig.ts.json",28 "typecheck-js": "tsc -p tsconfig.js.json",29 "test-all": "npm run test && npm run lint && npm run typecheck-js && npm run test-esm"30 },31 "files": [32 "index.js",33 "lib/*.js",
47 unmodified lines
added:tsconfig.js.json+13 added
1{ /* 2 Simple override including just JavaScript files.3 Used by npm run-script typecheck-js4 */5 /* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */6 "extends": "./tsconfig.json",7 "include": [8 /* All JavaScript targets from tsconfig.json include. */9 "*.js",10 "*.mjs",11 "lib/**/*.js"12 ],13}
modified:tsconfig.json+45 added-17 removed
1{2 "compilerOptions": {3 "module": "commonjs",4 "lib": [5 "es6"6 ],7 "noImplicitAny": true,8 "noImplicitThis": true,9 "strictNullChecks": true,10 "types": [11 "node",12 "jest"13 ],14 "esModuleInterop": true, // Mainly so can test an import problem which only occurs with this option on!15 "noEmit": true,16 "forceConsistentCasingInFileNames": true17 },18 "include": ["**/*.ts"],2 /*3 TypeScript is being used to do type checking across both JavaScript and TypeScript files.4 In particular, this picks up some problems in the JSDoc in the JavaScript files, and validates the code5 is consistent with the JSDoc.6 7 The settings here are used by VSCode.8 9 See also tsconfig.js.json and tsconfig.ts.json.10 */11 /* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */12 "compilerOptions": {13 "lib": ["es2021"],14 "module": "node16",15 "target": "es2021",1617 "allowJs": true,18 "checkJs": true,19 20 /* Strict by default, but dial it down to reduce churn in our JavaScript code. */21 "strict": true,22 "noImplicitAny": false, 23 "strictNullChecks": false,24 "useUnknownInCatchVariables": false,2526 "types": [27 "node",28 "jest"29 ],30 "noEmit": true, /* just type checking and not emitting transpiled files */31 "skipLibCheck": false, /* we want to check our hand crafted definitions */32 "forceConsistentCasingInFileNames": true,33 "esModuleInterop": true /* common TypeScript config */34 },35 "include": [36 /* JavaScript. Should match includes in tsconfig.js.json. */37 "*.js",38 "*.mjs",39 "lib/**/*.js",40 /* TypeScript. Should match includes in tsconfig.ts.json. */41 "**/*.ts",42 "**/*.mts"43 ],44 "exclude": [45 "node_modules"46 ]47}
added:tsconfig.ts.json+20 added
1{ /* 2 Override to include just TypeScript files and use stricter settings than we do with JavaScript.3 Used by:4 - npm run-script typecheck-ts5 - eslint6 */7 /* Visit https://aka.ms/tsconfig to read more about tsconfig configuration. */8 "extends": "./tsconfig.json",9 "compilerOptions": {10 /* Full strict is fine for the TypeScript files, so turn back on the checks we turned off for mixed-use. */11 "noImplicitAny": true, 12 "strictNullChecks": true,13 "useUnknownInCatchVariables": true,14 },15 "include": [16 /* All TypeScript targets from tsconfig.json include. */17 "**/*.ts",18 "**/*.mts"19 ],20}