diff --git a/package.json b/package.json index 5fa3019a..095ae11d 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,11 @@ "dependencies": { "common-tags": "^1.4.0", "dlv": "^1.1.0", - "eslint": "^4.5.0", + "eslint": "^4.0.0", "indent-string": "^3.2.0", "lodash.merge": "^4.6.0", "loglevel-colored-level-prefix": "^1.0.0", - "prettier": "^1.9.0", + "prettier": "^1.7.0", "pretty-format": "^22.0.3", "require-relative": "^0.8.7", "typescript": "^2.5.1", diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 8938a5c6..a6c4e49e 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -351,24 +351,6 @@ test("calls prettier.resolveConfig.sync with the file path", () => { expect(prettierMock.resolveConfig.sync).toHaveBeenCalledWith(filePath); }); -test("does not raise an error if prettier.resolveConfig.sync is not defined", () => { - const filePath = require.resolve("../../tests/fixtures/paths/foo.js"); - const originalPrettierMockResolveConfigSync = prettierMock.resolveConfig.sync; - prettierMock.resolveConfig.sync = undefined; - - function callingFormat() { - return format({ - filePath, - text: defaultInputText(), - eslintConfig: getESLintConfigWithDefaultRules() - }); - } - - expect(callingFormat).not.toThrowError(); - - prettierMock.resolveConfig.sync = originalPrettierMockResolveConfigSync; -}); - test("logs if there is a problem making the CLIEngine", () => { const error = new Error("fake error"); eslintMock.CLIEngine.mockImplementation(() => { diff --git a/src/index.js b/src/index.js index 764ffa9c..d00f659c 100644 --- a/src/index.js +++ b/src/index.js @@ -56,13 +56,13 @@ function format(options) { const eslintConfig = merge( {}, options.eslintConfig, - getConfig(filePath, eslintPath) + getESLintConfig(filePath) ); const prettierOptions = merge( {}, filePath && { filepath: filePath }, - getPrettierConfig(filePath, prettierPath), + getPrettierConfig(filePath), options.prettierOptions ); @@ -203,7 +203,7 @@ function getTextFromFilePath(filePath) { } } -function getConfig(filePath, eslintPath) { +function getESLintConfig(filePath) { const eslintOptions = {}; if (filePath) { eslintOptions.cwd = path.dirname(filePath); @@ -214,10 +214,10 @@ function getConfig(filePath, eslintPath) { "${filePath || process.cwd()}" ` ); - const configFinder = getESLintCLIEngine(eslintPath, eslintOptions); + const cliEngine = getESLintCLIEngine("eslint", eslintOptions); try { logger.debug(`getting eslint config for file at "${filePath}"`); - const config = configFinder.getConfigForFile(filePath); + const config = cliEngine.getConfigForFile(filePath); logger.trace( `eslint config for "${filePath}" received`, prettyFormat(config) @@ -230,14 +230,9 @@ function getConfig(filePath, eslintPath) { } } -function getPrettierConfig(filePath, prettierPath) { - const prettier = requireModule(prettierPath, "prettier"); - - // NOTE: Backward-compatibility with old prettier versions (<1.7) - // that don't have ``resolveConfig.sync` method. - return typeof prettier.resolveConfig.sync === "undefined" - ? {} - : prettier.resolveConfig.sync(filePath); +function getPrettierConfig(filePath) { + const prettier = requireModule("prettier", "prettier"); + return prettier.resolveConfig.sync(filePath); } function requireModule(modulePath, name) {