diff --git a/.eslintrc.js b/.eslintrc.js index a15835fc21..aaed6f6ebc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,14 +24,36 @@ module.exports = { }, plugins: ['@typescript-eslint', 'jest', 'jsdoc'], rules: { - 'prettier/prettier': 'error', - 'no-unused-vars': 'off', // let typescript-eslint handle this - 'no-console': 'error', - 'linebreak-style': 'off', + 'arrow-body-style': 'warn', + 'arrow-parens': ['off', 'always'], + 'brace-style': ['off', 'off'], + camelcase: 'warn', + 'class-methods-use-this': 'warn', 'comma-dangle': 'off', + complexity: 'off', 'constructor-super': 'error', + curly: ['warn', 'multi-line'], + 'default-case': 'error', + 'dot-notation': 'error', + 'eol-last': 'off', + eqeqeq: ['error', 'smart'], 'for-direction': ['error'], 'getter-return': 'warn', + 'guard-for-in': 'error', + 'id-match': 'error', + 'jsdoc/check-alignment': 'error', + 'jsdoc/check-indentation': 'error', + 'jsdoc/newline-after-description': 'warn', + 'linebreak-style': 'off', + 'max-classes-per-file': 'off', + 'max-len': 'off', + 'new-parens': 'off', + 'newline-per-chained-call': 'off', + 'no-bitwise': 'off', + 'no-caller': 'error', + 'no-duplicate-imports': 'error', + 'no-eval': 'error', + 'no-console': 'error', 'no-async-promise-executor': ['error'], 'no-case-declarations': ['error'], 'no-class-assign': ['error'], @@ -61,33 +83,71 @@ module.exports = { 'no-func-assign': ['error'], 'no-global-assign': ['error'], 'no-inner-declarations': ['error'], + 'no-invalid-this': 'off', 'no-invalid-regexp': ['error'], 'no-irregular-whitespace': 'off', 'no-misleading-character-class': ['error'], 'no-mixed-spaces-and-tabs': ['error'], + 'no-multiple-empty-lines': 'off', 'no-new-symbol': ['error'], + 'no-new-wrappers': 'error', 'no-obj-calls': ['error'], 'no-octal': ['error'], 'no-prototype-builtins': ['error'], 'no-redeclare': 'warn', 'no-regex-spaces': ['error'], + 'no-return-await': 'error', 'no-self-assign': ['error'], + 'no-shadow': [ + 'off', + { + hoist: 'all', + }, + ], 'no-shadow-restricted-names': ['error'], 'no-sparse-arrays': ['error'], + 'no-template-curly-in-string': 'error', 'no-this-before-super': ['error'], + 'no-throw-literal': 'error', + 'no-trailing-spaces': 'off', + 'no-undef-init': 'error', + 'no-underscore-dangle': 'off', + 'no-unused-expressions': 'error', 'no-undef': ['error'], 'no-unexpected-multiline': ['error'], 'no-unreachable': ['error'], 'no-unsafe-finally': 'error', 'no-unsafe-negation': ['error'], 'no-unused-labels': 'error', + 'no-unused-vars': 'off', // let typescript-eslint handle this 'no-useless-catch': ['error'], 'no-useless-escape': 'warn', + 'no-var': 'error', 'no-with': ['error'], + 'object-shorthand': 'error', + 'one-var': ['error', 'never'], + 'padding-line-between-statements': [ + "error", + { blankLine: "always", prev: "*", next: "return" } + ], + 'prefer-const': 'error', + 'prefer-object-spread': 'error', + 'prefer-template': 'error', + 'prettier/prettier': 'error', + 'quote-props': 'off', + radix: 'error', 'require-yield': ['error'], + 'space-before-function-paren': 'off', + 'space-in-parens': ['off', 'never'], + 'spaced-comment': [ + 'warn', + 'always', + { + markers: ['/'], + }, + ], 'use-isnan': 'error', 'valid-typeof': 'off', - '@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }], '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/array-type': [ 'warn', @@ -95,6 +155,7 @@ module.exports = { default: 'array', }, ], + '@typescript-eslint/ban-ts-ignore': 'off', '@typescript-eslint/ban-types': [ 'error', { @@ -120,12 +181,9 @@ module.exports = { }, }, ], - '@typescript-eslint/prefer-regexp-exec': 'warn', - '@typescript-eslint/prefer-string-starts-ends-with': 'warn', - '@typescript-eslint/unbound-method': 'off', - '@typescript-eslint/prefer-includes': 'warn', '@typescript-eslint/consistent-type-assertions': 'error', '@typescript-eslint/consistent-type-definitions': 'error', + '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-member-accessibility': [ 'error', { @@ -146,11 +204,9 @@ module.exports = { }, }, ], - '@typescript-eslint/require-await': 'off', - '@typescript-eslint/ban-ts-ignore': 'off', + '@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }], '@typescript-eslint/no-empty-function': ['error', { 'allow': ['arrowFunctions']}], '@typescript-eslint/no-empty-interface': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-for-in-array': 'error', '@typescript-eslint/no-inferrable-types': 'error', @@ -163,13 +219,18 @@ module.exports = { '@typescript-eslint/no-unsafe-member-access': 'off', '@typescript-eslint/no-unsafe-return': 'off', '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'warn', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/prefer-includes': 'warn', + '@typescript-eslint/prefer-regexp-exec': 'warn', + '@typescript-eslint/prefer-string-starts-ends-with': 'warn', '@typescript-eslint/prefer-for-of': 'off', '@typescript-eslint/prefer-function-type': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', '@typescript-eslint/prefer-readonly': 'error', + '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/require-await': 'off', '@typescript-eslint/triple-slash-reference': [ 'error', { @@ -179,65 +240,8 @@ module.exports = { }, ], '@typescript-eslint/type-annotation-spacing': 'off', + '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unified-signatures': 'error', - '@typescript-eslint/no-unnecessary-type-assertion': 'warn', - 'arrow-body-style': 'warn', - 'arrow-parens': ['off', 'always'], - 'brace-style': ['off', 'off'], - camelcase: 'warn', - 'class-methods-use-this': 'warn', - complexity: 'off', - curly: ['warn', 'multi-line'], - 'default-case': 'error', - 'dot-notation': 'error', - 'eol-last': 'off', - eqeqeq: ['error', 'smart'], - 'guard-for-in': 'error', - 'id-match': 'error', - 'jsdoc/check-alignment': 'error', - 'jsdoc/check-indentation': 'error', - 'jsdoc/newline-after-description': 'warn', - 'max-classes-per-file': 'off', - 'max-len': 'off', - 'new-parens': 'off', - 'newline-per-chained-call': 'off', - 'no-bitwise': 'off', - 'no-caller': 'error', - 'no-duplicate-imports': 'error', - 'no-eval': 'error', - 'no-invalid-this': 'off', - 'no-multiple-empty-lines': 'off', - 'no-new-wrappers': 'error', - 'no-return-await': 'error', - 'no-shadow': [ - 'off', - { - hoist: 'all', - }, - ], - 'no-template-curly-in-string': 'error', - 'no-throw-literal': 'error', - 'no-trailing-spaces': 'off', - 'no-undef-init': 'error', - 'no-underscore-dangle': 'off', - 'no-unused-expressions': 'error', - 'no-var': 'error', - 'object-shorthand': 'error', - 'one-var': ['error', 'never'], - 'prefer-const': 'warn', - 'prefer-object-spread': 'error', - 'prefer-template': 'error', - 'quote-props': 'off', - radix: 'error', - 'space-before-function-paren': 'off', - 'space-in-parens': ['off', 'never'], - 'spaced-comment': [ - 'warn', - 'always', - { - markers: ['/'], - }, - ], }, settings: {}, } diff --git a/e2e/__helpers__/test-case/run-descriptor.ts b/e2e/__helpers__/test-case/run-descriptor.ts index 64793eb744..bf8545f57c 100644 --- a/e2e/__helpers__/test-case/run-descriptor.ts +++ b/e2e/__helpers__/test-case/run-descriptor.ts @@ -101,6 +101,7 @@ function createIteratorContext(templateName: string, expectedStatus?: number): R if (status == null) { return 'run' } + return status === 0 ? 'pass' : 'fail' } diff --git a/e2e/__helpers__/test-case/run-result.ts b/e2e/__helpers__/test-case/run-result.ts index 9249dcf89f..7c0a521fb4 100644 --- a/e2e/__helpers__/test-case/run-result.ts +++ b/e2e/__helpers__/test-case/run-result.ts @@ -36,6 +36,7 @@ export default class RunResult { const lines = this.logFileContent.split(/\n/g) // remove last, empty line lines.pop() + return lines.map(s => JSON.parse(s)) } diff --git a/e2e/__helpers__/test-case/runtime.ts b/e2e/__helpers__/test-case/runtime.ts index 78fbeae94d..268f86efd9 100644 --- a/e2e/__helpers__/test-case/runtime.ts +++ b/e2e/__helpers__/test-case/runtime.ts @@ -49,6 +49,7 @@ function hooksSourceWith(vars: Record): string { if (!__hooksSource) { __hooksSource = readFileSync(join(__dirname, '__hooks-source__.js.hbs'), 'utf8') } + // eslint-disable-next-line no-useless-escape return __hooksSource.replace(/\{\{([^\}]+)\}\}/g, (_, key) => JSON.stringify(vars[key])) } @@ -253,6 +254,7 @@ export function prepareTest(name: string, template: string, options: RunTestOpti segments.pop() } snapshotDirs[segments.join(sep)] = 0 + return false } else if (relPath === 'jest.config.js') { // extend base if it's a function @@ -263,8 +265,10 @@ export function prepareTest(name: string, template: string, options: RunTestOpti const mod = require(src) if (typeof mod === 'function') { writeFileSync(dest, `module.exports = ${JSON.stringify(mod(baseConfig, configUtils))}`) + return false } + return true } else { return true diff --git a/e2e/__helpers__/test-case/utils.ts b/e2e/__helpers__/test-case/utils.ts index d271abc370..19d7573a21 100644 --- a/e2e/__helpers__/test-case/utils.ts +++ b/e2e/__helpers__/test-case/utils.ts @@ -12,6 +12,7 @@ export function templateNameForPath(path: string): string { if (existsSync(e2eFile)) { return require(e2eFile).template || 'default' } + return 'default' } @@ -21,6 +22,7 @@ const FAIL_MARKS = ['×', '✕'] const normalizeTestMark = (mark: string): string => { if (PASS_MARKS.includes(mark)) return PASS_MARKS[0] if (FAIL_MARKS.includes(mark)) return FAIL_MARKS[0] + return '?' } @@ -41,6 +43,7 @@ export function normalizeJestOutput(output: string): string { if (process.platform === 'win32') { out = out.replace(/\\/g, '/') } + return out } diff --git a/scripts/e2e.js b/scripts/e2e.js index a7f7287bd0..829608e61a 100755 --- a/scripts/e2e.js +++ b/scripts/e2e.js @@ -31,6 +31,7 @@ function getDirectories(rootDir) { function sha1(...data) { const hash = createHash('sha1') data.forEach((item) => hash.update(item)) + return hash.digest('hex').toString() } @@ -105,6 +106,7 @@ function setupE2e() { // no package-lock.json => this template doesn't provide any package-set if (!fs.existsSync(pkgLockFile)) { log(` [template: ${name}]`, 'not a package-set template, nothing to do') + return } @@ -119,6 +121,7 @@ function setupE2e() { if (bundleOk && packagesOk) { log(` [template: ${name}]`, 'bundle and packages unchanged, nothing to do') logPackageVersions() + return } } diff --git a/scripts/lib/bundle.js b/scripts/lib/bundle.js index c23a7f647c..33da5de2a4 100644 --- a/scripts/lib/bundle.js +++ b/scripts/lib/bundle.js @@ -42,6 +42,7 @@ function computePackageDigest(noWriteFile = false) { if (!noWriteFile) { writeFileSync(pkgDigestFile, digest, 'utf8') } + return digest } diff --git a/scripts/lib/npm.js b/scripts/lib/npm.js index b87a23186b..419ef7083e 100644 --- a/scripts/lib/npm.js +++ b/scripts/lib/npm.js @@ -22,6 +22,7 @@ function directDepsPkg(dir) { if (res[key]) return res[key] = require(join(dir, 'node_modules', key, 'package.json')) }) + return res } diff --git a/scripts/lib/spawn-sync.js b/scripts/lib/spawn-sync.js index eceaac9d2e..017247c8e2 100644 --- a/scripts/lib/spawn-sync.js +++ b/scripts/lib/spawn-sync.js @@ -15,6 +15,7 @@ const spawnSync = (...args) => { msgs.push('unknown error') throw new Error(msgs.find((s) => s)) } + return res } diff --git a/src/__helpers__/fakers.ts b/src/__helpers__/fakers.ts index fcb261a47c..cce96601fa 100644 --- a/src/__helpers__/fakers.ts +++ b/src/__helpers__/fakers.ts @@ -37,6 +37,7 @@ export function getJestConfig( if (tsJestOptions) { res.globals['ts-jest'] = tsJestOptions } + return res } diff --git a/src/__helpers__/mocks.ts b/src/__helpers__/mocks.ts index 3b3faa7cb8..ec92e02769 100644 --- a/src/__helpers__/mocks.ts +++ b/src/__helpers__/mocks.ts @@ -24,6 +24,7 @@ export const mockObject = (obj: T, newProps: M): T & M & { mockRestore: () Object.keys(backup).forEach((key) => { Object.defineProperty(obj, key, backup[key]) }) + return obj }, configurable: true, diff --git a/src/__helpers__/processed-source.ts b/src/__helpers__/processed-source.ts index 2e9ead49a9..6f0a4e5911 100644 --- a/src/__helpers__/processed-source.ts +++ b/src/__helpers__/processed-source.ts @@ -29,6 +29,7 @@ export default class ProcessedSource { get normalizedOutputSourceMaps(): RawSourceMap | undefined { const maps = this.outputSourceMaps if (maps) return this.sourceMapsNormalizer(maps) + return undefined } get sourceMapsNormalizer() { diff --git a/src/__helpers__/source-maps.ts b/src/__helpers__/source-maps.ts index 1c0bfd8e75..7d0ba2b25f 100644 --- a/src/__helpers__/source-maps.ts +++ b/src/__helpers__/source-maps.ts @@ -25,12 +25,14 @@ export function parseSource(source: string): ParsedSourceWithMaps { [] if (b64Maps) { const map = base64ToSourceMaps(b64Maps) + return { source: source.substr(0, -comment.length), comment: comment.trim(), sourceMaps: map, } } + return { source } } @@ -47,6 +49,7 @@ export function relativisePaths(map: RawSourceMap, fromPath: string, newPrefix = if (res.sourceRoot) res.sourceRoot = remap(res.sourceRoot) if (res.sources) res.sources = res.sources.map(remap) if (res.file) res.file = remap(res.file) + return res } @@ -56,6 +59,7 @@ export function rewriteSourceMaps(source: string, sourceMapsTransformer: (maps: (_, before, base64, after) => { let map = base64ToSourceMaps(base64) map = sourceMapsTransformer(map) + return `${before}${sourceMapsToBase64(map)}${after}` }, ) diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index 743f045819..85cbfb3d0f 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -21,6 +21,7 @@ const runCli = async ( mockedProcess.argv.splice(2, mockedProcess.argv.length - 2, ...args) lastExitCode = undefined await processArgv() + return { exitCode: lastExitCode, stdout: mockedProcess.stdout.written.join('\n'), diff --git a/src/cli/config/migrate.ts b/src/cli/config/migrate.ts index d15d42a854..9098a17c9d 100644 --- a/src/cli/config/migrate.ts +++ b/src/cli/config/migrate.ts @@ -49,8 +49,10 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger*/) => let transformer: string = (migratedConfig.transform as any)[pattern] if (/\bbabel-jest\b/.test(transformer)) transformer = 'babel-jest' else if (/\ts-jest\b/.test(transformer)) transformer = 'ts-jest' + return [...list, transformer] } + return list }, [] as string[]) // depending on the transformer found, we use one or the other preset @@ -132,6 +134,7 @@ Visit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more inf process.stderr.write(` No migration needed for given Jest configuration `) + return } diff --git a/src/cli/index.ts b/src/cli/index.ts index 5962ecd802..ed88dc9adf 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -24,6 +24,7 @@ async function cli(args: string[]): Promise { js(val: string) { const res = val.trim().toLowerCase() if (!['babel', 'ts'].includes(res)) throw new Error(`The 'js' option must be 'babel' or 'ts', given: '${val}'.`) + return res }, }, diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 49b53421eb..227b4e4596 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -104,6 +104,7 @@ const toDiagnosticCodeList = (items: any, into: number[] = []): number[] => { const code = toDiagnosticCode(item) if (code && !into.includes(code)) into.push(code) } + return into } @@ -156,6 +157,7 @@ export class ConfigSet { ...pkg.devDependencies, ...pkg.dependencies, }) + return names.reduce((map, name) => { const version = getPackageVersion(name) if (version) map[name] = version @@ -393,6 +395,7 @@ export class ConfigSet { } = this if (babelConfig == null) { this.logger.debug('babel is disabled') + return undefined } let base: BabelConfig = { cwd: this.cwd } @@ -434,6 +437,7 @@ export class ConfigSet { const { babel } = this if (!babel) return undefined this.logger.debug('creating babel-jest transformer') + return importer.babelJest(ImportReasons.BabelJest).createTransformer(babel) as BabelJestTransformer } @@ -471,6 +475,7 @@ export class ConfigSet { return importer.tryTheseOr(hooksFile, {}) } + return {} } @@ -565,6 +570,7 @@ export class ConfigSet { get tsCacheDir(): string | undefined { if (!this.jest.cache) { logger.debug('file caching disabled') + return undefined } const cacheSuffix = sha1( @@ -580,6 +586,7 @@ export class ConfigSet { ) const res = join(this.jest.cacheDirectory, 'ts-jest', cacheSuffix.substr(0, 2), cacheSuffix.substr(2)) logger.debug({ cacheDirectory: res }, 'will use file caching') + return res } @@ -694,6 +701,7 @@ export class ConfigSet { options: { category?: DiagnosticCategory; file?: SourceFile; start?: number; length?: number } = {}, ): Diagnostic { const { category = this.compilerModule.DiagnosticCategory.Warning, file, start, length } = options + return { code, messageText, @@ -828,6 +836,7 @@ export class ConfigSet { throw new Error(interpolate(Errors.FileNotFound, { inputPath, resolvedPath: path })) } this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path) + return path } diff --git a/src/config/paths-to-module-name-mapper.ts b/src/config/paths-to-module-name-mapper.ts index f1b1338c8c..d41f3fc322 100644 --- a/src/config/paths-to-module-name-mapper.ts +++ b/src/config/paths-to-module-name-mapper.ts @@ -49,5 +49,6 @@ export const pathsToModuleNameMapper = ( continue } } + return jestMap } diff --git a/src/index.spec.ts b/src/index.spec.ts index 4705cfefec..94ecaf3e31 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -10,6 +10,7 @@ jest.mock('./ts-jest-transformer', () => { getCacheKey: jest.Mock = jest.fn() constructor(public opt?: any) {} } + return { TsJestTransformer } }) jest.mock('./config/create-jest-preset', () => ({ diff --git a/src/transformers/hoist-jest.ts b/src/transformers/hoist-jest.ts index 7054fc28ff..36af0cecde 100644 --- a/src/transformers/hoist-jest.ts +++ b/src/transformers/hoist-jest.ts @@ -136,6 +136,7 @@ export function factory(cs: ConfigSet): (ctx: TransformationContext) => Transfor // finally returns the currently visited node return resultNode } + return visitor } diff --git a/src/util/get-package-version.ts b/src/util/get-package-version.ts index 4ffd70626e..7dcae74719 100644 --- a/src/util/get-package-version.ts +++ b/src/util/get-package-version.ts @@ -5,5 +5,6 @@ export function getPackageVersion(moduleName: string): string | undefined { try { return require(`${moduleName}/package.json`).version as string } catch (err) {} + return } diff --git a/src/util/importer.ts b/src/util/importer.ts index 60c797b85d..f351f52335 100644 --- a/src/util/importer.ts +++ b/src/util/importer.ts @@ -19,6 +19,7 @@ interface ImportOptions { const passThru = (action: () => void) => (input: any) => { action() + return input } @@ -29,6 +30,7 @@ export class Importer { @Memoize() static get instance(): Importer { logger.debug('creating Importer singleton') + // here we can define patches to apply to modules. // it could be fixes that are not deployed, or // abstractions so that multiple versions work the same @@ -107,8 +109,10 @@ export class Importer { protected _patch(name: string, unpatched: T): T { if (name in this._patches) { logger.debug('patching', name) + return this._patches[name].reduce((mod, patcher) => patcher(mod), unpatched) } + return unpatched } @@ -181,6 +185,7 @@ function requireWrapper(moduleName: string): RequireResult { result.error = error } } + return result } diff --git a/src/util/json.ts b/src/util/json.ts index 03af44d50a..8b40c9b09f 100644 --- a/src/util/json.ts +++ b/src/util/json.ts @@ -33,6 +33,7 @@ export function normalize(input: string, { parse: parser = parse }: NormalizeOpt if (result === input) result = undefined normalize.cache.set(input, result) } + return result === undefined ? input : result } diff --git a/src/util/memoize.ts b/src/util/memoize.ts index d792f6c0bc..07266d5f2e 100644 --- a/src/util/memoize.ts +++ b/src/util/memoize.ts @@ -56,6 +56,7 @@ function memoize( if (cache.has(key)) return cache.get(key) const res: any = func.apply(this, args) cache.set(key, res) + return res } } diff --git a/src/util/sha1.ts b/src/util/sha1.ts index 8fbe2322d6..ec383d47e5 100644 --- a/src/util/sha1.ts +++ b/src/util/sha1.ts @@ -34,5 +34,6 @@ export function sha1(...data: DataItem[]): string { if (canCache) { cache[cacheKey] = res } + return res } diff --git a/src/util/version-checkers.ts b/src/util/version-checkers.ts index f93f3d4726..19d0f3e586 100644 --- a/src/util/version-checkers.ts +++ b/src/util/version-checkers.ts @@ -71,6 +71,7 @@ function checkVersion( logger.fatal(message) throw new RangeError(message) } + return success } @@ -82,9 +83,11 @@ function createVersionChecker(moduleName: string, expectedVersion: string): Vers let memo: boolean | undefined const warn = () => { if (memo !== undefined) return memo + return (memo = checkVersion(moduleName, expectedVersion, 'warn')) } const raise = () => checkVersion(moduleName, expectedVersion, 'throw') + return { raise, warn,