Skip to content

Commit

Permalink
If no file config found lookup from process.cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
David Clark committed Oct 16, 2016
1 parent 6c12fa2 commit c1e9894
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/__tests__/standalone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,23 @@ test("standalone with different configs per file", t => {
}).catch(t.end)
})

test("standalone with config locatable from process.cwd not file", t => {
const actualCwd = process.cwd()
process.chdir(path.join(__dirname, "./fixtures/getConfigForFile/a/b"))
standalone({
files: [path.join(__dirname, "./fixtures/empty-block.css")],
}).then(({ results }) => {
const result = results[0]
t.equal(result.warnings.length, 2, "two warning")
t.ok(result.warnings[0].text.indexOf("Unexpected empty block") !== -1, "first correct warning")
t.ok(result.warnings[1].text.indexOf("foo") !== -1, "second correct warning")

process.chdir(actualCwd)
t.end()
}).catch((err) => {
process.chdir(actualCwd)
t.end(err)
})
})

function logError(err) { console.log(err.stack) } // eslint-disable-line no-console
5 changes: 5 additions & 0 deletions src/getConfigForFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default function (
}

return stylelint._fullExplorer.load(searchPath, stylelint._options.configFile)
.then((config) => {
// If no config was found, try looking from process.cwd
if (!config) return stylelint._fullExplorer.load(process.cwd())
return config
})
.then((config) => {
if (!config) {
const ending = (searchPath) ? ` for ${searchPath}` : ""
Expand Down

0 comments on commit c1e9894

Please sign in to comment.