diff --git a/__mocks__/glob.js b/__mocks__/glob.js index 8e1e6da..01b6254 100644 --- a/__mocks__/glob.js +++ b/__mocks__/glob.js @@ -1,73 +1,94 @@ -module.exports = jest.fn(function mockGlob(globString, options, callback) { +const glob = jest.fn(async function mockGlob(globString) { /* eslint complexity:0 */ if (globString.includes('1')) { - callback(null, [ + return [ fredProject('index.js'), fredProject('start.js'), fredProject('stop/index.js'), fredProject('stop/log.js') - ]); - } else if (globString.includes('2')) { - callback(null, [ + ]; + } + + if (globString.includes('2')) { + return [ fredProject('index.js'), fredProject('start.js'), fredProject('continue/index.js'), fredProject('continue/forever.js') - ]); - } else if (globString.includes('node_modules')) { - callback(null, [ + ]; + } + + if (globString.includes('node_modules')) { + return [ fredProject('foo/node_modules/stuff1.js'), fredProject('foo/node_modules/stuff2.js'), fredProject('foo/node_modules/stuff3.js') - ]); - } else if (globString.includes('files-with-syntax-errors')) { - callback(null, [ - fredProject('syntax-error1.js'), - fredProject('syntax-error2.js') - ]); - } else if (globString.includes('no-match')) { - callback(null, []); - } else if (globString.includes('throw-error')) { - callback(new Error('something weird happened')); - } else if (globString.includes('no-change')) { - callback(null, [ + ]; + } + + if (globString.includes('files-with-syntax-errors')) { + return [fredProject('syntax-error1.js'), fredProject('syntax-error2.js')]; + } + + if (globString.includes('no-match')) { + return []; + } + + if (globString.includes('throw-error')) { + throw new Error('something weird happened'); + } + + if (globString.includes('no-change')) { + return [ fredProject('no-change/1.js'), fredProject('no-change/2.js'), fredProject('no-change/3.js') - ]); - } else if (globString.includes('eslintignored')) { - callback(null, [ + ]; + } + + if (globString.includes('eslintignored')) { + return [ fredProject('eslintignored1.js'), fredProject('eslintignored2.js'), fredProject('eslintignored3.js'), fredProject('applied4.js') - ]); - } else if (globString.includes('prettierignored')) { - callback(null, [ + ]; + } + + if (globString.includes('prettierignored')) { + return [ fredProject('prettierignored1.js'), fredProject('prettierignored2.js'), fredProject('prettierignored3.js'), fredProject('applied4.js') - ]); - } else if (globString.includes('no-ignore')) { - callback(null, [ + ]; + } + + if (globString.includes('no-ignore')) { + return [ barneyProject('no-ignore/1.js'), barneyProject('no-ignore/2.js'), barneyProject('no-ignore/3.js') - ]); - } else if (globString.includes('eslint-config-error')) { - callback(null, [ + ]; + } + + if (globString.includes('eslint-config-error')) { + return [ fredProject('eslint-config-error/1.js'), fredProject('eslint-config-error/2.js') - ]); - } else { - throw new Error( - `Your test globString: "${globString}"` + - " doesn't have associated mock data." - ); + ]; } + + throw new Error( + `Your test globString: "${globString}"` + + " doesn't have associated mock data." + ); }); +glob.glob = glob; + +exports.glob = glob; + function fredProject(path) { return `/Users/fredFlintstone/Developer/top-secret/footless-carriage/${path}`; } diff --git a/jest.config.js b/jest.config.js index 34b3381..5565617 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,7 @@ module.exports = { testEnvironment: 'node', // TODO: test all the files... // collectCoverageFrom: ['src/**/*.js'], - testPathIgnorePatterns: ['/node_modules/', '/fixtures/'], + testPathIgnorePatterns: ['/node_modules/', '/fixtures/', '/dist/'], coveragePathIgnorePatterns: ['/node_modules/', '/fixtures/', '/dist/'], coverageThreshold: { global: { diff --git a/package.json b/package.json index 6c0ab4c..612b357 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "CLI for prettier-eslint", "main": "dist/no-main.js", "engines": { - "node": ">=12.22" + "node": ">=16.0.0" }, "bin": { "prettier-eslint": "dist/index.js" @@ -39,44 +39,44 @@ } }, "dependencies": { - "@messageformat/core": "^3.0.1", - "@prettier/eslint": "npm:prettier-eslint@^15.0.1", + "@messageformat/core": "^3.2.0", + "@prettier/eslint": "npm:prettier-eslint@^16.0.0", "arrify": "^2.0.1", "boolify": "^1.0.1", - "camelcase-keys": "^7.0.2", + "camelcase-keys": "^9.1.0", "chalk": "^4.1.2", "common-tags": "^1.8.2", - "core-js": "^3.24.1", - "eslint": "^8.21.0", + "core-js": "^3.33.0", + "eslint": "^8.51.0", "find-up": "^5.0.0", "get-stdin": "^8.0.0", - "glob": "^7.2.3", - "ignore": "^5.2.0", + "glob": "^10.3.10", + "ignore": "^5.2.4", "indent-string": "^4.0.0", "lodash.memoize": "^4.1.2", "loglevel-colored-level-prefix": "^1.0.0", - "rxjs": "^7.5.6", - "yargs": "^13.1.1" + "rxjs": "^7.8.1", + "yargs": "^17.7.2" }, "devDependencies": { - "@babel/cli": "^7.18.10", - "@babel/core": "^7.18.10", - "@babel/node": "^7.18.10", - "@babel/preset-env": "^7.18.10", - "@changesets/changelog-github": "^0.4.6", - "@changesets/cli": "^2.24.3", - "all-contributors-cli": "^6.20.0", - "clean-pkg-json": "^1.0.1", - "eslint-config-kentcdodds": "^20.3.1", - "eslint-plugin-node-dependencies": "^0.8.0", - "jest": "^28.1.3", - "lint-staged": "^12.5.0", + "@babel/cli": "^7.23.0", + "@babel/core": "^7.23.2", + "@babel/node": "^7.22.19", + "@babel/preset-env": "^7.23.2", + "@changesets/changelog-github": "^0.4.8", + "@changesets/cli": "^2.26.2", + "all-contributors-cli": "^6.26.1", + "clean-pkg-json": "^1.2.0", + "eslint-config-kentcdodds": "^20.5.0", + "eslint-plugin-node-dependencies": "^0.11.0", + "jest": "^29.7.0", + "lint-staged": "^14.0.1", "nps": "^5.10.0", "nps-utils": "^1.7.0", - "patch-package": "^6.4.7", + "patch-package": "^8.0.0", "pify": "^5.0.0", - "rimraf": "^3.0.2", - "simple-git-hooks": "^2.8.0", + "rimraf": "^5.0.5", + "simple-git-hooks": "^2.9.0", "spawn-command": "0.0.2-1", "strip-indent": "^3.0.0", "yargs-parser": "^21.1.1" diff --git a/patches/@rushstack+eslint-patch+1.1.4.patch b/patches/@rushstack+eslint-patch+1.1.4.patch deleted file mode 100644 index fffc953..0000000 --- a/patches/@rushstack+eslint-patch+1.1.4.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js b/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js -index 6d665b7..888509d 100644 ---- a/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js -+++ b/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js -@@ -198,7 +198,7 @@ if (!ConfigArrayFactory.__patched) { - try { - ModuleResolver.resolve = function (moduleName, relativeToPath) { - // resolve using ctx.filePath instead of relativeToPath -- return originalResolve.call(this, moduleName, ctx.filePath); -+ return originalResolve.call(this, moduleName, ctx.filePath || relativeToPath); - }; - return originalLoadPlugin.apply(this, arguments); - } diff --git a/patches/eslint-config-kentcdodds+20.3.1.patch b/patches/eslint-config-kentcdodds+20.3.1.patch deleted file mode 100644 index a956c41..0000000 --- a/patches/eslint-config-kentcdodds+20.3.1.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/node_modules/eslint-config-kentcdodds/jest.js b/node_modules/eslint-config-kentcdodds/jest.js -index a13e618..81bbc4b 100644 ---- a/node_modules/eslint-config-kentcdodds/jest.js -+++ b/node_modules/eslint-config-kentcdodds/jest.js -@@ -30,7 +30,7 @@ try { - - module.exports = { - env: { -- 'jest/globals': true, -+ jest: true, - }, - plugins: [ - 'jest', diff --git a/src/__snapshots__/uncaught-exception-handler.test.js.snap b/src/__snapshots__/uncaught-exception-handler.test.js.snap index bfdb4b6..9221aca 100644 --- a/src/__snapshots__/uncaught-exception-handler.test.js.snap +++ b/src/__snapshots__/uncaught-exception-handler.test.js.snap @@ -2,7 +2,7 @@ exports[`logs a check for trace 1`] = ` "There has been an unknown error when running the prettier-eslint CLI. If it's unclear to you what went wrong, then try this: - ✅ Run the script again with the LOG_LEVEL environment variable set to \\"trace\\" + ✅ Run the script again with the LOG_LEVEL environment variable set to "trace" 2. Search existing issues on GitHub: https://github.com/prettier/prettier-eslint-cli/issues?utf8=%E2%9C%93&q=my%20error 3. Make a minimal reproduction in a totally separate repository. You can fork this one: https://github.com/kentcdodds/prettier-eslint-cli-repro 4. Post an issue with a link to your reproduction to the issues on GitHub: https://github.com/prettier/prettier-eslint-cli/issues/new" @@ -10,7 +10,7 @@ exports[`logs a check for trace 1`] = ` exports[`logs all options 1`] = ` "There has been an unknown error when running the prettier-eslint CLI. If it's unclear to you what went wrong, then try this: - 1. Run the script again with the LOG_LEVEL environment variable set to \\"trace\\" + 1. Run the script again with the LOG_LEVEL environment variable set to "trace" 2. Search existing issues on GitHub: https://github.com/prettier/prettier-eslint-cli/issues?utf8=%E2%9C%93&q=my%20error 3. Make a minimal reproduction in a totally separate repository. You can fork this one: https://github.com/kentcdodds/prettier-eslint-cli-repro 4. Post an issue with a link to your reproduction to the issues on GitHub: https://github.com/prettier/prettier-eslint-cli/issues/new" diff --git a/src/format-files.js b/src/format-files.js index 4f79e3b..3cce097 100644 --- a/src/format-files.js +++ b/src/format-files.js @@ -2,7 +2,7 @@ /* eslint complexity:[1, 7] */ import path from 'path'; import fs from 'fs'; -import glob from 'glob'; +import { glob } from 'glob'; import { bindNodeCallback, from, of } from 'rxjs'; import { catchError, concatAll, distinct, map, mergeMap } from 'rxjs/operators'; import chalk from 'chalk'; @@ -16,7 +16,6 @@ import format from './prettier-eslint'; import * as messages from './messages'; const LINE_SEPERATOR_REGEX = /(\r|\n|\r\n)/; -const rxGlob = bindNodeCallback(glob); const rxReadFile = bindNodeCallback(fs.readFile); const rxWriteFile = bindNodeCallback(fs.writeFile); const findUpEslintignoreSyncMemoized = memoize( @@ -165,7 +164,8 @@ function formatFilesFromGlobs({ } function onComplete() { - const isSilent = logger.getLevel() === logger.levels.SILENT || cliOptions.listDifferent; + const isSilent = + logger.getLevel() === logger.levels.SILENT || cliOptions.listDifferent; /* use console.error directly here because * - we don't want these messages prefixed @@ -219,7 +219,7 @@ function getFilesFromGlob( // not smart unless you explicitly include it in your glob globOptions.ignore.push('**/node_modules/**'); } - return rxGlob(fileGlob, globOptions).pipe( + return from(glob(fileGlob, globOptions)).pipe( map(filePaths => { return filePaths.filter(filePath => { if (applyEslintIgnore && isFilePathMatchedByEslintignore(filePath)) { diff --git a/src/format-files.test.js b/src/format-files.test.js index 4718391..9ab27a2 100644 --- a/src/format-files.test.js +++ b/src/format-files.test.js @@ -1,7 +1,7 @@ /* eslint no-console:0 */ import fsMock from 'fs'; import findUpMock from 'find-up'; -import globMock from 'glob'; +import { glob as globMock } from 'glob'; import mockGetStdin from 'get-stdin'; import getLogger from 'loglevel-colored-level-prefix'; import formatMock from './prettier-eslint'; @@ -43,8 +43,7 @@ test('glob call inclues an ignore of node_modules', async () => { const globOptions = expect.objectContaining({ ignore: expect.arrayContaining(['**/node_modules/**']) }); - const callback = expect.any(Function); - expect(globMock).toHaveBeenCalledWith(fileGlob, globOptions, callback); + expect(globMock).toHaveBeenCalledWith(fileGlob, globOptions); }); test('glob call excludes an ignore of node_modules', async () => { @@ -55,8 +54,7 @@ test('glob call excludes an ignore of node_modules', async () => { expect.objectContaining({ // should not have an ignore with **/node_modules/** ignore: expect.arrayContaining(['**/node_modules/**']) - }), - expect.any + }) ); }); @@ -189,8 +187,7 @@ test('allows you to specify an ignore glob', async () => { const globOptions = expect.objectContaining({ ignore: [...ignore, '**/node_modules/**'] }); - const callback = expect.any(Function); - expect(globMock).toHaveBeenCalledWith(fileGlob, globOptions, callback); + expect(globMock).toHaveBeenCalledWith(fileGlob, globOptions); }); test('wont modify a file if it is eslint ignored', async () => { diff --git a/src/parser.js b/src/parser.js index 29c6122..65b1a38 100644 --- a/src/parser.js +++ b/src/parser.js @@ -226,7 +226,7 @@ const parser = yargs // TODO: support range-start and range-end // would require changes in prettier-eslint }) - .strict(); + .strictOptions(); export default parser; diff --git a/test/tests/__snapshots__/cli.spec.js.snap b/test/tests/__snapshots__/cli.spec.js.snap index e5821bd..2e34ccf 100644 --- a/test/tests/__snapshots__/cli.spec.js.snap +++ b/test/tests/__snapshots__/cli.spec.js.snap @@ -6,7 +6,7 @@ exports[`prettier-eslint --version: stdout: --version 1`] = ` `; exports[`prettier-eslint test/fixtures/example*.js --write --no-eslint-ignore --no-prettier-ignore: file contents: prettier-eslint test/fixtures/example*.js --write --no-eslint-ignore --no-prettier-ignore 1`] = ` -Object { +{ "example1Result": "const { example1 } = baz.bar; ", "example2Result": "function example2(thing) {