diff --git a/dist/cli.js b/dist/cli.js index 314cddf..9bd9629 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -83,7 +83,7 @@ async function lintStdIn(linter, options) { } // If we performed fixes then maybe return the fixed text if (options.fix) { - if (lintReport.results[0].output !== undefined) { + if (lintReport.results[0].output != null) { // Code contained fixable errors, so print the fixed code process.stdout.write(lintReport.results[0].output); } @@ -118,7 +118,7 @@ async function printReport(lintReport, options) { // Check for any fixable rules const isFixable = lintReport.results.some((res) => { return res.messages.some((msg) => { - return msg.fix !== undefined; + return msg.fix != null; }); }); // If there were fixable rules, then that means that `--fix` was not provided diff --git a/dist/options/default-options.js b/dist/options/default-options.js index 75bc8e1..5405ff9 100644 --- a/dist/options/default-options.js +++ b/dist/options/default-options.js @@ -35,6 +35,7 @@ function _getTSConfigFromDefaultLocations(cwd) { return absPath; } } + return undefined; } exports._getTSConfigFromDefaultLocations = _getTSConfigFromDefaultLocations; function _isValidPath(pathToValidate) { diff --git a/dist/options/package-options.js b/dist/options/package-options.js index 9b42e39..a0343ae 100644 --- a/dist/options/package-options.js +++ b/dist/options/package-options.js @@ -26,11 +26,12 @@ function getPackageOptions(cwd) { } exports.getPackageOptions = getPackageOptions; function _resolveTSConfigPath(cwd, settingsProjectPath) { - if (settingsProjectPath !== undefined) { + if (settingsProjectPath != null) { const settingsPath = path_1.join(cwd, settingsProjectPath); if (default_options_1._isValidPath(settingsPath)) { return settingsPath; } } + return undefined; } exports._resolveTSConfigPath = _resolveTSConfigPath; diff --git a/package.json b/package.json index 8e8e877..94ed3a1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "jest", "coverage": "npm test -- --coverage", "coveralls": "coveralls < coverage/lcov.info", - "lint": "prettier --write '**/*.{ts*,js*,yml}' && bin/cmd.js --fix && tsc --noEmit", + "lint": "prettier --write '**/*.{ts*,js*,yml}' && bin/cmd.js --fix && tsc -p './tsconfig.eslint.json' --noEmit", "build": "tsc", "watch": "tsc -w" }, @@ -125,6 +125,7 @@ }, "prettier": { "singleQuote": true, - "semi": false + "semi": false, + "trailingComma": "none" } } diff --git a/src/cli.test.ts b/src/cli.test.ts index 0198d4a..47c8a8f 100644 --- a/src/cli.test.ts +++ b/src/cli.test.ts @@ -13,7 +13,7 @@ const mockCustomReporter = jest.fn() jest.mock('custom-reporter', () => mockCustomReporter, { virtual: true }) jest.mock('custom-bad-reporter', () => undefined, { virtual: true }) -const mockStylish = stylish as jest.MockedFunction +const mockStylish = stylish as jest.MockedFunction const mockGetStdin = getStdin as jest.MockedFunction const mockProcess = process diff --git a/src/cli.ts b/src/cli.ts index 758b357..7e258f8 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,5 +1,5 @@ import type * as eslint from 'eslint' -import type { LintReport, LintResult } from 'standard-engine' +import type { LintReport, LintResult, LintMessage } from 'standard-engine' import * as getStdin from 'get-stdin' import { getCLIOptions, @@ -128,7 +128,7 @@ export async function lintStdIn ( // If we performed fixes then maybe return the fixed text if (options.fix) { - if (lintReport.results[0].output !== undefined) { + if (lintReport.results[0].output != null) { // Code contained fixable errors, so print the fixed code process.stdout.write(lintReport.results[0].output) } else { @@ -170,9 +170,9 @@ export async function printReport ( console.error(`${CMD}: ${TAGLINE} (${HOMEPAGE})`) // Check for any fixable rules - const isFixable: boolean = lintReport.results.some((res: any) => { - return res.messages.some((msg: any) => { - return msg.fix !== undefined + const isFixable: boolean = lintReport.results.some((res: LintResult) => { + return res.messages.some((msg: LintMessage) => { + return msg.fix != null }) }) diff --git a/src/options/default-options.ts b/src/options/default-options.ts index fe6151e..7f8d8cc 100644 --- a/src/options/default-options.ts +++ b/src/options/default-options.ts @@ -55,6 +55,7 @@ export function _getTSConfigFromDefaultLocations ( return absPath } } + return undefined } export function _isValidPath (pathToValidate: string): boolean { diff --git a/src/options/package-options.ts b/src/options/package-options.ts index 190d6c2..f4f5980 100644 --- a/src/options/package-options.ts +++ b/src/options/package-options.ts @@ -60,10 +60,11 @@ export function _resolveTSConfigPath ( cwd: string, settingsProjectPath?: string ): string | undefined { - if (settingsProjectPath !== undefined) { + if (settingsProjectPath != null) { const settingsPath = join(cwd, settingsProjectPath) if (_isValidPath(settingsPath)) { return settingsPath } } + return undefined } diff --git a/src/standard-engine-api.test.ts b/src/standard-engine-api.test.ts index b843500..dea6301 100644 --- a/src/standard-engine-api.test.ts +++ b/src/standard-engine-api.test.ts @@ -1,6 +1,13 @@ +import type { + lintFiles as lintFilesType, + lintText as lintTextType, + parseOpts as parseOptsType +} from './standard-engine-api' import * as tsStandardLib from './ts-standard' -let parseOpts: Function, lintFiles: any, lintText: any +let parseOpts: typeof parseOptsType, + lintFiles: typeof lintFilesType, + lintText: typeof lintTextType jest.mock('standard-engine') const customEslint = jest.fn().mockReturnThis() @@ -98,7 +105,7 @@ describe('standard-engine-api', () => { lintTextSpy.mockResolvedValueOnce('success!') expect.assertions(6) - lintText(text, (err: any, res: any) => { + lintText(text, (err, res) => { try { expect(err).toBeUndefined() expect(res).toEqual('success!') @@ -118,7 +125,7 @@ describe('standard-engine-api', () => { lintTextSpy.mockResolvedValueOnce('success!') expect.assertions(6) - lintText(text, options, (err: any, res: any) => { + lintText(text, options, (err, res) => { try { expect(err).toBeUndefined() expect(res).toEqual('success!') @@ -140,7 +147,7 @@ describe('standard-engine-api', () => { expect.assertions(3) parseOpts({}) expect(tsStandardSpy).toHaveBeenCalledTimes(1) - lintText(text, options, (err: any, res: any) => { + lintText(text, options, (err) => { try { expect(err).toBeUndefined() expect(tsStandardSpy).toHaveBeenCalledTimes(1) @@ -156,9 +163,9 @@ describe('standard-engine-api', () => { lintTextSpy.mockRejectedValueOnce(new Error('the darkside')) expect.assertions(3) - lintText(text, options, (err: { message: any }, res: any) => { + lintText(text, options, (err, res) => { try { - expect(err.message).toMatch(/the darkside/gi) + expect(err?.message).toMatch(/the darkside/gi) expect(tsStandardSpy).toHaveBeenCalledTimes(1) expect(res).toBeUndefined() cb() @@ -178,7 +185,7 @@ describe('standard-engine-api', () => { { filename: 'file:///some/path/to/the/darkside' }, - (err: any, res: any) => { + (err, res) => { try { expect(err).toBeUndefined() expect(res).toEqual('success!') @@ -220,7 +227,7 @@ describe('standard-engine-api', () => { lintFilesSpy.mockResolvedValueOnce('success!') expect.assertions(6) - lintFiles(files, (err: any, res: any) => { + lintFiles(files, (err, res) => { try { expect(err).toBeUndefined() expect(res).toEqual('success!') @@ -240,7 +247,7 @@ describe('standard-engine-api', () => { lintFilesSpy.mockResolvedValueOnce('success!') expect.assertions(6) - lintFiles(files, options, (err: any, res: any) => { + lintFiles(files, options, (err, res) => { try { expect(err).toBeUndefined() expect(res).toEqual('success!') @@ -262,7 +269,7 @@ describe('standard-engine-api', () => { expect.assertions(3) parseOpts({}) expect(tsStandardSpy).toHaveBeenCalledTimes(1) - lintFiles(files, options, (err: any, res: any) => { + lintFiles(files, options, (err) => { try { expect(err).toBeUndefined() expect(tsStandardSpy).toHaveBeenCalledTimes(1) @@ -278,9 +285,9 @@ describe('standard-engine-api', () => { lintFilesSpy.mockRejectedValueOnce(new Error('the darkside')) expect.assertions(3) - lintFiles(files, options, (err: { message: any }, res: any) => { + lintFiles(files, options, (err, res) => { try { - expect(err.message).toMatch(/the darkside/gi) + expect(err?.message).toMatch(/the darkside/gi) expect(tsStandardSpy).toHaveBeenCalledTimes(1) expect(res).toBeUndefined() cb() diff --git a/src/ts-standard.test.ts b/src/ts-standard.test.ts index 6302ed7..89aad8b 100644 --- a/src/ts-standard.test.ts +++ b/src/ts-standard.test.ts @@ -125,7 +125,7 @@ describe('ts-standard', () => { it('should lint the given text with default options', async (): Promise => { const text = 'The darkside is strong in this one.' - lintTextSpy.mockImplementationOnce((text, options, cb) => + lintTextSpy.mockImplementationOnce((_text, _options, cb) => cb(undefined, 'success!') ) const res = await tsStandard.lintText(text) @@ -138,7 +138,7 @@ describe('ts-standard', () => { it('should overide default options with method options', async (): Promise => { const text = 'The darkside is strong in this one.' - lintTextSpy.mockImplementationOnce((text, options, cb) => + lintTextSpy.mockImplementationOnce((_text, _options, cb) => cb(undefined, 'success!') ) const newOptions = { @@ -158,7 +158,7 @@ describe('ts-standard', () => { it('should return error if linting failed', async (): Promise => { const text = 'The darkside is strong in this one.' - lintTextSpy.mockImplementationOnce((text, options, cb) => + lintTextSpy.mockImplementationOnce((_text, _options, cb) => cb(new Error('the darkside')) ) expect.assertions(2) @@ -194,7 +194,7 @@ describe('ts-standard', () => { it('should lint the given files with default options', async (): Promise => { const files = ['The darkside is strong in this one.'] - lintFilesSpy.mockImplementationOnce((files, options, cb) => + lintFilesSpy.mockImplementationOnce((_files, _options, cb) => cb(undefined, 'success!') ) const res = await tsStandard.lintFiles(files) @@ -207,7 +207,7 @@ describe('ts-standard', () => { it('should overide default options with method options', async (): Promise => { const files = ['The darkside is strong in this one.'] - lintFilesSpy.mockImplementationOnce((files, options, cb) => + lintFilesSpy.mockImplementationOnce((_files, _options, cb) => cb(undefined, 'success!') ) const newOptions = { @@ -227,7 +227,7 @@ describe('ts-standard', () => { it('should return error if linting failed', async (): Promise => { const files = ['The darkside is strong in this one.'] - lintFilesSpy.mockImplementationOnce((files, options, cb) => + lintFilesSpy.mockImplementationOnce((_files, _options, cb) => cb(new Error('the darkside')) ) expect.assertions(2) diff --git a/src/types/stylish.d.ts b/src/types/stylish.d.ts index 5e6974c..15beb2e 100644 --- a/src/types/stylish.d.ts +++ b/src/types/stylish.d.ts @@ -1,3 +1,7 @@ declare module 'eslint/lib/cli-engine/formatters/stylish' { - export {} + import type { LintResult } from 'standard-engine' + + function stylish (results: LintResult[]): string + namespace stylish {} + export = stylish } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index a77c899..54a50dd 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -8,7 +8,13 @@ "resolveJsonModule": true, "lib": ["es2018", "es2019", "es2020"], "allowJs": true, - "checkJs": true + "checkJs": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "newLine": "lf", + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true }, - "include": ["src/**/*.ts", "bin/*.js", "*.json"] + "include": ["src", "bin", "*.json"] } diff --git a/tsconfig.json b/tsconfig.json index b113d36..9574c22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,15 @@ "strict": true, "declaration": true, "resolveJsonModule": true, - "lib": ["es2018", "es2019", "es2020"] + "lib": ["es2018", "es2019", "es2020"], + "allowJs": true, + "checkJs": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "newLine": "lf", + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true }, "include": ["src/**/*.ts"], "exclude": ["src/**/*.test.ts"]