diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000000..04f32be0f134 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Make sure baseline files have consistent line endings +*.txt text eol=lf +*.snap text eol=lf +*.debug-check text eol=lf \ No newline at end of file diff --git a/azure-pipelines-tests.yml b/azure-pipelines-tests.yml new file mode 100644 index 000000000000..7197b9880ec2 --- /dev/null +++ b/azure-pipelines-tests.yml @@ -0,0 +1,19 @@ +steps: +- task: NodeTool@0 + inputs: + versionSpec: '$(node_version)' + displayName: 'Install Node.js' + +- script: npm install -g yarn + displayName: 'Get yarn' + +- script: yarn install + displayName: 'yarn install' + +- script: yarn test + displayName: 'Test' + +- task: PublishTestResults@2 + inputs: + testResultsFiles: '**/junit.xml' + condition: succeededOrFailed() diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000000..7a323b1d11a6 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,109 @@ +trigger: +- master +- releases/* + +jobs: + +# Build and test on Windows +- job: Test_Windows + displayName: Tests on Windows Node8 + pool: + vmImage: vs2017-win2016 + variables: + node_version: 8.x + report_summaries: true + steps: + - template: azure-pipelines-tests.yml + +# Build and test on macOS +- job: Test_macOS + displayName: Tests on macOS Node8 + pool: + vmImage: macos-10.13 + variables: + node_version: 8.x + report_summaries: true + steps: + - template: azure-pipelines-tests.yml + +# Test on Linux +- job: Test_Linux + displayName: Run tests + pool: + vmImage: 'Ubuntu 16.04' + strategy: + matrix: + Node8: + node_version: '8.x' + Node11: + node_version: '11.x' + variables: + report_summaries: true + steps: + - template: azure-pipelines-tests.yml + +# Test production bundle on Linux using Node 4 +- job: Prod_Linux + displayName: Test production bundle on Linux + pool: + vmImage: 'Ubuntu 16.04' + strategy: + matrix: + Node4: + node_version: '4.x' + Node9: + node_version: '9.x' + steps: + - task: NodeTool@0 + inputs: + versionSpec: '11.x' + displayName: 'Install Node.js' + + - script: npm install -g yarn + displayName: 'Get yarn' + + - script: yarn install + displayName: 'yarn install' + + - script: yarn check-deps + displayName: 'Check dependencies' + + - script: yarn build + displayName: 'Build' + + - task: NodeTool@0 + inputs: + versionSpec: '$(node_version)' + displayName: 'Use Node.js $(node_version)' + + - script: npm install -g yarn@1.5 + displayName: 'Get yarn compatible with node 4' + condition: eq(variables['node_version'], '4.x') + + - script: node ./scripts/test-dist.js + displayName: 'Test' + + - task: PublishTestResults@2 + inputs: + testResultsFiles: '**/junit.xml' + condition: and(variables['report_summaries'], succeededOrFailed()) + +# Lint checks on Linux +- job: Lint_linux + displayName: Lint (Linux) + pool: + vmImage: 'Ubuntu 16.04' + steps: + - task: NodeTool@0 + inputs: + versionSpec: '8.x' + displayName: 'Install Node.js' + + - script: yarn install + displayName: 'yarn install' + + - script: yarn lint + displayName: 'Lint code' + + - script: yarn lint-docs + displayName: 'Lint docs' \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index c837041ac2d4..1b6f86a6ed4a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,9 +17,13 @@ module.exports = { "jest-snapshot-serializer-ansi" ], testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", - testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat( - isOldNode ? requiresPrettierInternals : [] - ), + testPathIgnorePatterns: ["tests/new_react", "tests/more_react"] + .concat(isOldNode ? requiresPrettierInternals : []) + .concat( + require("os").EOL == "\n" + ? ["tests_integration/__tests__/eol-crlf.js"] + : ["tests_integration/__tests__/eol-lf.js"] + ), collectCoverage: ENABLE_COVERAGE, collectCoverageFrom: ["src/**/*.js", "index.js", "!/node_modules/"], coveragePathIgnorePatterns: [ diff --git a/tests/windows/__snapshots__/jsfmt.spec.js.snap b/tests/windows/__snapshots__/jsfmt.spec.js.snap deleted file mode 100644 index 6980c269cd22..000000000000 --- a/tests/windows/__snapshots__/jsfmt.spec.js.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`line-ending.js - flow-verify 1`] = ` -this; -has; -windows; -line; -endings; -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -this; -has; -windows; -line; -endings; - -`; - -exports[`template.js - flow-verify 1`] = ` -const aLongString = \` -Line 1 -Line 2 -Line 3 -Line 4 -Line 5 -\`; -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -const aLongString = \` -Line 1 -Line 2 -Line 3 -Line 4 -Line 5 -\`; - -`; diff --git a/tests/windows/jsfmt.spec.js b/tests/windows/jsfmt.spec.js deleted file mode 100644 index a842e1348721..000000000000 --- a/tests/windows/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(__dirname, ["flow", "typescript"]); diff --git a/tests/windows/line-ending.js b/tests/windows/line-ending.js deleted file mode 100644 index 65eb8ff78071..000000000000 --- a/tests/windows/line-ending.js +++ /dev/null @@ -1,5 +0,0 @@ -this; -has; -windows; -line; -endings; diff --git a/tests/windows/template.js b/tests/windows/template.js deleted file mode 100644 index 5b9e637adc51..000000000000 --- a/tests/windows/template.js +++ /dev/null @@ -1,7 +0,0 @@ -const aLongString = ` -Line 1 -Line 2 -Line 3 -Line 4 -Line 5 -`; diff --git a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap index 0e3519797f91..c23a07772445 100644 --- a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap @@ -3,17 +3,7 @@ exports[`CLI overrides take precedence (stderr) 1`] = `""`; exports[`CLI overrides take precedence (stdout) 1`] = ` -"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/ - console.log(/*CR*/ - \\"line endings should be CRLF\\"/*CR*/ - )/*CR*/ -}/*CR*/ -function f() { - console.log( - \\"line endings should be LF\\" - ) -} -function f() { +"function f() { console.log( \\"should have tab width 8\\" ) @@ -50,6 +40,8 @@ function js() { \\"use strict\\"; module.exports = { + endOfLine: + \\"lf\\", tabWidth: 8 }; function noConfigJs() { @@ -124,13 +116,7 @@ exports[`resolves configuration file with --find-config-path file (write) 1`] = exports[`resolves configuration from external files (stderr) 1`] = `""`; exports[`resolves configuration from external files (stdout) 1`] = ` -"function f() {/*CR*/ console.log(\\"line endings should be CR\\")/*CR*/}/*CR*/function f() {/*CR*/ - console.log(\\"line endings should be CRLF\\")/*CR*/ -}/*CR*/ -function f() { - console.log(\\"line endings should be LF\\") -} -function f() { +"function f() { console.log(\\"should have tab width 8\\") } function f() { @@ -153,6 +139,7 @@ function js() { \\"use strict\\"; module.exports = { + endOfLine: \\"lf\\", tabWidth: 8 }; function noConfigJs() { diff --git a/tests_integration/__tests__/__snapshots__/eol-crlf.js.snap b/tests_integration/__tests__/__snapshots__/eol-crlf.js.snap new file mode 100644 index 000000000000..07511e6156a9 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/eol-crlf.js.snap @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Has correct default Windows line endings (stderr) 1`] = `""`; + +exports[`Has correct default Windows line endings (stdout) 1`] = ` +"function f() { + console.log(\\"should have tab width 8\\") +} +function f() { + console.log(\\"should have space width 2\\") +} +function f() { + console.log(\\"should have space width 8\\") +} +function f() { + console.log( + \\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\" + ) +} +console.log(\\"jest/__best-tests__/file.js should have semi\\");/*CR*/ +console.log(\\"jest/Component.js should not have semi\\")/*CR*/ +console.log(\\"jest/Component.test.js should have semi\\");/*CR*/ +function js() { + console.log(\\"js/file.js should have tab width 8 (1 if CLI)\\"); +} +\\"use strict\\"; + +module.exports = { + endOfLine: \\"lf\\", + tabWidth: 8 +}; +function noConfigJs() { + console.log(\\"no-config/file.js should have no semicolons\\") +} +function packageJs() {/*CR*/ + console.log(\\"package/file.js should have tab width 3\\");/*CR*/ +}/*CR*/ +function rcJson() {/*CR*/ + console.log.apply(null, [/*CR*/ + 'rc-json/file.js',/*CR*/ + 'should have trailing comma',/*CR*/ + 'and single quotes',/*CR*/ + ]);/*CR*/ +}/*CR*/ +function rcToml() {/*CR*/ + console.log.apply(null, [/*CR*/ + 'rc-toml/file.js',/*CR*/ + 'should have trailing comma',/*CR*/ + 'and single quotes',/*CR*/ + ]);/*CR*/ +}/*CR*/ +function rcYaml() {/*CR*/ + console.log.apply(null, [/*CR*/ + 'rc-yaml/file.js',/*CR*/ + 'should have trailing comma',/*CR*/ + 'and single quotes',/*CR*/ + ]);/*CR*/ +}/*CR*/ +" +`; + +exports[`Has correct default Windows line endings (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/eol-lf.js.snap b/tests_integration/__tests__/__snapshots__/eol-lf.js.snap new file mode 100644 index 000000000000..02ef9a4faddc --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/eol-lf.js.snap @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Has correct default Unix line endings (stderr) 1`] = `""`; + +exports[`Has correct default Unix line endings (stdout) 1`] = ` +"function f() { + console.log(\\"should have tab width 8\\") +} +function f() { + console.log(\\"should have space width 2\\") +} +function f() { + console.log(\\"should have space width 8\\") +} +function f() { + console.log( + \\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\" + ) +} +console.log(\\"jest/__best-tests__/file.js should have semi\\"); +console.log(\\"jest/Component.js should not have semi\\") +console.log(\\"jest/Component.test.js should have semi\\"); +function js() { + console.log(\\"js/file.js should have tab width 8 (1 if CLI)\\"); +} +\\"use strict\\"; + +module.exports = { + endOfLine: \\"lf\\", + tabWidth: 8 +}; +function noConfigJs() { + console.log(\\"no-config/file.js should have no semicolons\\") +} +function packageJs() { + console.log(\\"package/file.js should have tab width 3\\"); +} +function rcJson() { + console.log.apply(null, [ + 'rc-json/file.js', + 'should have trailing comma', + 'and single quotes', + ]); +} +function rcToml() { + console.log.apply(null, [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ]); +} +function rcYaml() { + console.log.apply(null, [ + 'rc-yaml/file.js', + 'should have trailing comma', + 'and single quotes', + ]); +} +" +`; + +exports[`Has correct default Unix line endings (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap index 3ff3063e9652..9ac3ca80403a 100644 --- a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap @@ -54,6 +54,7 @@ exports[`CLI overrides gets ignored when config exists with --config-precedence \\"use strict\\"; module.exports = { + endOfLine: \\"lf\\", tabWidth: 8 }; " @@ -70,6 +71,7 @@ exports[`CLI overrides take lower precedence with --config-precedence file-overr \\"use strict\\"; module.exports = { + endOfLine: \\"lf\\", tabWidth: 8 }; " @@ -80,17 +82,7 @@ exports[`CLI overrides take lower precedence with --config-precedence file-overr exports[`CLI overrides take precedence with --config-precedence cli-override (stderr) 1`] = `""`; exports[`CLI overrides take precedence with --config-precedence cli-override (stdout) 1`] = ` -"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/ - console.log(/*CR*/ - \\"line endings should be CRLF\\"/*CR*/ - )/*CR*/ -}/*CR*/ -function f() { - console.log( - \\"line endings should be LF\\" - ) -} -function f() { +"function f() { console.log( \\"should have tab width 8\\" ) @@ -127,6 +119,8 @@ function js() { \\"use strict\\"; module.exports = { + endOfLine: + \\"lf\\", tabWidth: 8 }; function noConfigJs() { @@ -177,17 +171,7 @@ exports[`CLI overrides take precedence with --config-precedence cli-override (wr exports[`CLI overrides take precedence without --config-precedence (stderr) 1`] = `""`; exports[`CLI overrides take precedence without --config-precedence (stdout) 1`] = ` -"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/ - console.log(/*CR*/ - \\"line endings should be CRLF\\"/*CR*/ - )/*CR*/ -}/*CR*/ -function f() { - console.log( - \\"line endings should be LF\\" - ) -} -function f() { +"function f() { console.log( \\"should have tab width 8\\" ) @@ -224,6 +208,8 @@ function js() { \\"use strict\\"; module.exports = { + endOfLine: + \\"lf\\", tabWidth: 8 }; function noConfigJs() { diff --git a/tests_integration/__tests__/arg-parsing.js b/tests_integration/__tests__/arg-parsing.js index 36420e2d1779..0b76417b562f 100644 --- a/tests_integration/__tests__/arg-parsing.js +++ b/tests_integration/__tests__/arg-parsing.js @@ -3,37 +3,67 @@ const runPrettier = require("../runPrettier"); describe("boolean flags do not swallow the next argument", () => { - runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "--single-quote", + "file.js" + ]).test({ status: 0 }); }); describe("negated options work", () => { - runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "--no-semi", + "file.js" + ]).test({ status: 0 }); }); describe("unknown options are warned", () => { - runPrettier("cli/arg-parsing", ["file.js", "--unknown"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "file.js", + "--unknown" + ]).test({ status: 0 }); }); describe("unknown negated options are warned", () => { - runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "file.js", + "--no-unknown" + ]).test({ status: 0 }); }); describe("deprecated options are warned", () => { - runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "file.js", + "--flow-parser" + ]).test({ status: 0 }); }); describe("deprecated option values are warned", () => { - runPrettier("cli/arg-parsing", ["file.js", "--trailing-comma"]).test({ + runPrettier("cli/arg-parsing", [ + "--end-of-line", + "lf", + "file.js", + "--trailing-comma" + ]).test({ status: 0 }); }); diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js index 6072fde9796d..96ff204c6506 100644 --- a/tests_integration/__tests__/config-resolution.js +++ b/tests_integration/__tests__/config-resolution.js @@ -8,13 +8,13 @@ const prettier = require("prettier/local"); expect.addSnapshotSerializer(require("../path-serializer")); describe("resolves configuration from external files", () => { - runPrettier("cli/config/", ["**/*.js"]).test({ + runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({ status: 0 }); }); describe("resolves configuration from external files and overrides by extname", () => { - runPrettier("cli/config/", ["**/*.ts"]).test({ + runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.ts"]).test({ status: 0 }); }); @@ -50,14 +50,25 @@ describe("resolves toml configuration file with --find-config-path file", () => }); describe("prints nothing when no file found with --find-config-path", () => { - runPrettier("cli/config/", ["--find-config-path", ".."]).test({ + runPrettier("cli/config/", [ + "--end-of-line", + "lf", + "--find-config-path", + ".." + ]).test({ stdout: "", status: 1 }); }); describe("CLI overrides take precedence", () => { - runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({ + runPrettier("cli/config/", [ + "--end-of-line", + "lf", + "--print-width", + "1", + "**/*.js" + ]).test({ status: 0 }); }); diff --git a/tests_integration/__tests__/debug-check.js b/tests_integration/__tests__/debug-check.js index d0641ee64053..3d7ee2530218 100644 --- a/tests_integration/__tests__/debug-check.js +++ b/tests_integration/__tests__/debug-check.js @@ -22,6 +22,8 @@ describe("checks stdin with --debug-check", () => { describe("show diff for 2+ error files with --debug-check", () => { runPrettier("cli/debug-check", [ + "--end-of-line", + "lf", "*.debug-check", "--debug-check", "--plugin", diff --git a/tests_integration/__tests__/eol-crlf.js b/tests_integration/__tests__/eol-crlf.js new file mode 100644 index 000000000000..622cc915deaf --- /dev/null +++ b/tests_integration/__tests__/eol-crlf.js @@ -0,0 +1,11 @@ +"use strict"; + +const runPrettier = require("../runPrettier"); + +expect.addSnapshotSerializer(require("../path-serializer")); + +describe("Has correct default Windows line endings", () => { + runPrettier("cli/config/", ["**/*.js"]).test({ + status: 0 + }); +}); diff --git a/tests_integration/__tests__/eol-lf.js b/tests_integration/__tests__/eol-lf.js new file mode 100644 index 000000000000..e8730e65f3d6 --- /dev/null +++ b/tests_integration/__tests__/eol-lf.js @@ -0,0 +1,11 @@ +"use strict"; + +const runPrettier = require("../runPrettier"); + +expect.addSnapshotSerializer(require("../path-serializer")); + +describe("Has correct default Unix line endings", () => { + runPrettier("cli/config/", ["**/*.js"]).test({ + status: 0 + }); +}); diff --git a/tests_integration/__tests__/ignore-path.js b/tests_integration/__tests__/ignore-path.js index b4afa66e2c3c..f5ef0bed39af 100644 --- a/tests_integration/__tests__/ignore-path.js +++ b/tests_integration/__tests__/ignore-path.js @@ -26,7 +26,9 @@ describe("ignore file when using --debug-check", () => { }); describe("outputs files as-is if no --write", () => { - runPrettier("cli/ignore-path", ["regular-module.js"]).test({ + runPrettier("cli/ignore-path", ["regular-module.js"], { + ignoreLineEndings: true + }).test({ status: 0 }); }); diff --git a/tests_integration/__tests__/infer-parser.js b/tests_integration/__tests__/infer-parser.js index e5e766620166..da2d673fb1e0 100644 --- a/tests_integration/__tests__/infer-parser.js +++ b/tests_integration/__tests__/infer-parser.js @@ -49,7 +49,7 @@ describe("stdin with unknown path and no parser", () => { describe("unknown path and no parser", () => { describe("specific file", () => { - runPrettier("cli/infer-parser/", ["FOO"]).test({ + runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "FOO"]).test({ status: 2, stdout: "", write: [] @@ -57,7 +57,7 @@ describe("unknown path and no parser", () => { }); describe("multiple files", () => { - runPrettier("cli/infer-parser/", ["*"]).test({ + runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({ status: 2, write: [] }); diff --git a/tests_integration/__tests__/parser-api.js b/tests_integration/__tests__/parser-api.js index e1c25e2b6321..e3af8b1281ce 100644 --- a/tests_integration/__tests__/parser-api.js +++ b/tests_integration/__tests__/parser-api.js @@ -31,6 +31,8 @@ test("allows usage of prettier's supported parsers", () => { describe("allows passing a string to resolve a parser", () => { runPrettier("./custom-parsers/", [ + "--end-of-line", + "lf", "./custom-rename-input.js", "--parser", "./custom-rename-parser" diff --git a/tests_integration/__tests__/plugin-extensions.js b/tests_integration/__tests__/plugin-extensions.js index e13d3274693a..78169070149b 100644 --- a/tests_integration/__tests__/plugin-extensions.js +++ b/tests_integration/__tests__/plugin-extensions.js @@ -4,7 +4,9 @@ const runPrettier = require("../runPrettier"); const EOL = "\n"; describe("uses 'extensions' from languages to determine parser", () => { - runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"]).test({ + runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"], { + ignoreLineEndings: true + }).test({ stdout: "!contents" + EOL, stderr: "", status: 0, diff --git a/tests_integration/__tests__/plugin-preprocess.js b/tests_integration/__tests__/plugin-preprocess.js index ee6f97cb2dd8..9f6fba28445c 100644 --- a/tests_integration/__tests__/plugin-preprocess.js +++ b/tests_integration/__tests__/plugin-preprocess.js @@ -4,7 +4,9 @@ const runPrettier = require("../runPrettier"); const EOL = "\n"; describe("parser preprocess function is used to reshape input text", () => { - runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"]).test({ + runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"], { + ignoreLineEndings: true + }).test({ stdout: "preprocessed:contents" + EOL, stderr: "", status: 0, diff --git a/tests_integration/__tests__/plugin-resolution.js b/tests_integration/__tests__/plugin-resolution.js index 2e9a51d6f50c..645346a51495 100644 --- a/tests_integration/__tests__/plugin-resolution.js +++ b/tests_integration/__tests__/plugin-resolution.js @@ -74,11 +74,17 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (dif }); describe("does not crash when --plugin-search-dir does not contain node_modules", () => { - runPrettier("plugins/extensions", [ - "file.foo", - "--plugin=./plugin", - "--plugin-search-dir=." - ]).test({ + runPrettier( + "plugins/extensions", + [ + "file.foo", + "--end-of-line", + "lf", + "--plugin=./plugin", + "--plugin-search-dir=." + ], + { ignoreLineEndings: true } + ).test({ stdout: "!contents" + EOL, stderr: "", status: 0, diff --git a/tests_integration/__tests__/with-config-precedence.js b/tests_integration/__tests__/with-config-precedence.js index 19333c35fbd7..d1e58beefcf5 100644 --- a/tests_integration/__tests__/with-config-precedence.js +++ b/tests_integration/__tests__/with-config-precedence.js @@ -3,13 +3,21 @@ const runPrettier = require("../runPrettier"); describe("CLI overrides take precedence without --config-precedence", () => { - runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({ + runPrettier("cli/config/", [ + "--end-of-line", + "lf", + "--print-width", + "1", + "**/*.js" + ]).test({ status: 0 }); }); describe("CLI overrides take precedence with --config-precedence cli-override", () => { runPrettier("cli/config/", [ + "--end-of-line", + "lf", "--print-width", "1", "--config-precedence", @@ -22,6 +30,8 @@ describe("CLI overrides take precedence with --config-precedence cli-override", describe("CLI overrides take lower precedence with --config-precedence file-override", () => { runPrettier("cli/config/js/", [ + "--end-of-line", + "crlf", "--tab-width", "1", "--config-precedence", @@ -34,6 +44,8 @@ describe("CLI overrides take lower precedence with --config-precedence file-over describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { runPrettier("cli/config/no-config/", [ + "--end-of-line", + "lf", "--tab-width", "6", "--config-precedence", @@ -60,6 +72,8 @@ describe("CLI overrides gets ignored when config exists with --config-precedence describe("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { runPrettier("cli/config/no-config/", [ + "--end-of-line", + "lf", "--print-width", "1", "--tab-width", diff --git a/tests_integration/__tests__/with-parser-inference.js b/tests_integration/__tests__/with-parser-inference.js index a0b7ac8636d8..c8ca46a2ee5e 100644 --- a/tests_integration/__tests__/with-parser-inference.js +++ b/tests_integration/__tests__/with-parser-inference.js @@ -4,7 +4,7 @@ const runPrettier = require("../runPrettier"); const prettier = require("prettier/local"); describe("infers postcss parser", () => { - runPrettier("cli/with-parser-inference", ["*"]).test({ + runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({ status: 0 }); }); diff --git a/tests_integration/__tests__/with-shebang.js b/tests_integration/__tests__/with-shebang.js index e90f63633fde..ceda4c5c9fd2 100644 --- a/tests_integration/__tests__/with-shebang.js +++ b/tests_integration/__tests__/with-shebang.js @@ -3,7 +3,9 @@ const runPrettier = require("../runPrettier"); describe("preserves shebang", () => { - runPrettier("cli/with-shebang", ["issue1890.js"]).test({ - status: 0 - }); + runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test( + { + status: 0 + } + ); }); diff --git a/tests_integration/cli/config/.prettierrc b/tests_integration/cli/config/.prettierrc index 8f522b78c33d..7c221bcc11e9 100644 --- a/tests_integration/cli/config/.prettierrc +++ b/tests_integration/cli/config/.prettierrc @@ -1,3 +1,4 @@ +endOfLine: 'lf' overrides: - files: "*.js" options: diff --git a/tests_integration/cli/config/editorconfig/.editorconfig b/tests_integration/cli/config/editorconfig/.editorconfig index 15ea263a8ed3..8bd599323adc 100644 --- a/tests_integration/cli/config/editorconfig/.editorconfig +++ b/tests_integration/cli/config/editorconfig/.editorconfig @@ -12,14 +12,4 @@ indent_style = space indent_size = 2 [lib/indent_size=tab.js] -indent_size = tab - -# End of line (--eol opition) -[eol/cr.js] -end_of_line = cr - -[eol/crlf.js] -end_of_line = crlf - -[eol/lf.js] -end_of_line = lf +indent_size = tab \ No newline at end of file diff --git a/tests_integration/cli/config/editorconfig/eol/cr.js b/tests_integration/cli/config/editorconfig/eol/cr.js deleted file mode 100644 index 6d366df61d87..000000000000 --- a/tests_integration/cli/config/editorconfig/eol/cr.js +++ /dev/null @@ -1,3 +0,0 @@ -function f() { - console.log("line endings should be CR") -} diff --git a/tests_integration/cli/config/editorconfig/eol/crlf.js b/tests_integration/cli/config/editorconfig/eol/crlf.js deleted file mode 100644 index 8b25e5fd3202..000000000000 --- a/tests_integration/cli/config/editorconfig/eol/crlf.js +++ /dev/null @@ -1,3 +0,0 @@ -function f() { - console.log("line endings should be CRLF") -} diff --git a/tests_integration/cli/config/editorconfig/eol/lf.js b/tests_integration/cli/config/editorconfig/eol/lf.js deleted file mode 100644 index d17f615db592..000000000000 --- a/tests_integration/cli/config/editorconfig/eol/lf.js +++ /dev/null @@ -1,3 +0,0 @@ -function f() { - console.log("line endings should be LF") -} diff --git a/tests_integration/cli/config/js/prettier.config.js b/tests_integration/cli/config/js/prettier.config.js index a4b0c1d6b096..da1c5408e77c 100644 --- a/tests_integration/cli/config/js/prettier.config.js +++ b/tests_integration/cli/config/js/prettier.config.js @@ -1,5 +1,6 @@ "use strict"; module.exports = { + endOfLine: 'lf', tabWidth: 8 }; diff --git a/tests_integration/runPrettier.js b/tests_integration/runPrettier.js index b5dd75c62344..99e9a1ede9fd 100644 --- a/tests_integration/runPrettier.js +++ b/tests_integration/runPrettier.js @@ -111,8 +111,11 @@ function runPrettier(dir, args, options) { const value = // \r is trimmed from jest snapshots by default; // manually replacing this character with /*CR*/ to test its true presence + // If ignoreLineEndings is specified, \r is simply deleted instead typeof result[name] === "string" - ? stripAnsi(result[name]).replace(/\r/g, "/*CR*/") + ? options.ignoreLineEndings + ? stripAnsi(result[name]).replace(/\r/g, "") + : stripAnsi(result[name]).replace(/\r/g, "/*CR*/") : result[name]; if (name in testOptions) { if (name === "status" && testOptions[name] === "non-zero") {