forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI option '--config-precedence' (prettier#2733)
Add CLI option '--config-precedence'
- Loading branch information
1 parent
7eaf5c7
commit c59a82c
Showing
9 changed files
with
268 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CLI overrides are still applied when no config is found with --config-precedence file-override 1`] = ` | ||
"function f() { | ||
console.log(\\"should have no semicolons\\") | ||
} | ||
" | ||
`; | ||
|
||
exports[`CLI overrides gets applied when no config exists with --config-precedence prefer-file 1`] = ` | ||
"function f() { | ||
console.log( | ||
\\"should have no semicolons\\" | ||
); | ||
} | ||
" | ||
`; | ||
|
||
exports[`CLI overrides gets ignored when config exists with --config-precedence prefer-file 1`] = ` | ||
"function f() { | ||
console.log(\\"should have tab width 8\\"); | ||
} | ||
\\"use strict\\"; | ||
module.exports = { | ||
tabWidth: 8 | ||
}; | ||
" | ||
`; | ||
|
||
exports[`CLI overrides take lower precedence with --config-precedence file-override 1`] = ` | ||
"function f() { | ||
console.log(\\"should have tab width 8\\"); | ||
} | ||
\\"use strict\\"; | ||
module.exports = { | ||
tabWidth: 8 | ||
}; | ||
" | ||
`; | ||
|
||
exports[`CLI overrides take precedence with --config-precedence cli-override 1`] = ` | ||
"console.log( | ||
\\"should have semi\\" | ||
); | ||
console.log( | ||
\\"should not have semi\\" | ||
) | ||
console.log( | ||
\\"should have semi\\" | ||
); | ||
function f() { | ||
console.log( | ||
\\"should have tab width 8\\" | ||
); | ||
} | ||
\\"use strict\\"; | ||
module.exports = { | ||
tabWidth: 8 | ||
}; | ||
function f() { | ||
console.log( | ||
\\"should have no semicolons\\" | ||
) | ||
} | ||
function f() { | ||
console.log( | ||
\\"should have tab width 3\\" | ||
); | ||
} | ||
function f() { | ||
console.log.apply( | ||
null, | ||
[ | ||
'this file', | ||
'should have trailing comma', | ||
'and single quotes', | ||
], | ||
); | ||
} | ||
" | ||
`; | ||
|
||
exports[`CLI overrides take precedence without --config-precedence 1`] = ` | ||
"console.log( | ||
\\"should have semi\\" | ||
); | ||
console.log( | ||
\\"should not have semi\\" | ||
) | ||
console.log( | ||
\\"should have semi\\" | ||
); | ||
function f() { | ||
console.log( | ||
\\"should have tab width 8\\" | ||
); | ||
} | ||
\\"use strict\\"; | ||
module.exports = { | ||
tabWidth: 8 | ||
}; | ||
function f() { | ||
console.log( | ||
\\"should have no semicolons\\" | ||
) | ||
} | ||
function f() { | ||
console.log( | ||
\\"should have tab width 3\\" | ||
); | ||
} | ||
function f() { | ||
console.log.apply( | ||
null, | ||
[ | ||
'this file', | ||
'should have trailing comma', | ||
'and single quotes', | ||
], | ||
); | ||
} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"use strict"; | ||
|
||
const runPrettier = require("../runPrettier"); | ||
|
||
test("CLI overrides take precedence without --config-precedence", () => { | ||
const output = runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); | ||
|
||
test("CLI overrides take precedence with --config-precedence cli-override", () => { | ||
const output = runPrettier("cli/config/", [ | ||
"--print-width", | ||
"1", | ||
"--config-precedence", | ||
"cli-override", | ||
"**/*.js" | ||
]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); | ||
|
||
test("CLI overrides take lower precedence with --config-precedence file-override", () => { | ||
const output = runPrettier("cli/config/js/", [ | ||
"--tab-width", | ||
"1", | ||
"--config-precedence", | ||
"file-override", | ||
"**/*.js" | ||
]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); | ||
|
||
test("CLI overrides are still applied when no config is found with --config-precedence file-override", () => { | ||
const output = runPrettier("cli/config/no-config/", [ | ||
"--tab-width", | ||
"6", | ||
"--config-precedence", | ||
"file-override", | ||
"**/*.js" | ||
]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); | ||
|
||
test("CLI overrides gets ignored when config exists with --config-precedence prefer-file", () => { | ||
const output = runPrettier("cli/config/js/", [ | ||
"--print-width", | ||
"1", | ||
"--tab-width", | ||
"1", | ||
"--config-precedence", | ||
"prefer-file", | ||
"**/*.js" | ||
]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); | ||
|
||
test("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => { | ||
const output = runPrettier("cli/config/no-config/", [ | ||
"--print-width", | ||
"1", | ||
"--tab-width", | ||
"7", | ||
"--no-config", | ||
"--config-precedence", | ||
"prefer-file", | ||
"**/*.js" | ||
]); | ||
expect(output.stdout).toMatchSnapshot(); | ||
expect(output.status).toEqual(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"config-precedence": "invalidValue" | ||
} |