Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e327558
commit 2dd1834
Showing
8 changed files
with
183 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const pluginWarnAboutFoo = require("./fixtures/plugin-warn-about-foo"); | ||
const printConfig = require("../printConfig"); | ||
|
||
it("printConfig uses getConfigForFile to retrieve the config", () => { | ||
const filepath = path.join( | ||
__dirname, | ||
"fixtures/getConfigForFile/a/b/foo.css" | ||
); | ||
printConfig({ | ||
files: [filepath] | ||
}).then(result => { | ||
expect(result).toEqual({ | ||
plugins: [path.join(__dirname, "/fixtures/plugin-warn-about-foo.js")], | ||
rules: { | ||
"block-no-empty": [true], | ||
"plugin/warn-about-foo": ["always"] | ||
}, | ||
pluginFunctions: { | ||
"plugin/warn-about-foo": pluginWarnAboutFoo.rule | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
it("printConfig with input css should throw", () => { | ||
expect( | ||
printConfig({ | ||
code: "a {}" | ||
}) | ||
).rejects.toThrow( | ||
"The --print-config option must be used with exactly one file path." | ||
); | ||
}); | ||
|
||
it("printConfig with no path should throw", () => { | ||
expect( | ||
printConfig({ | ||
files: [] | ||
}) | ||
).rejects.toThrow( | ||
"The --print-config option must be used with exactly one file path." | ||
); | ||
}); | ||
|
||
it("printConfig with multiple paths should throw", () => { | ||
expect( | ||
printConfig({ | ||
files: ["./first-path.css", "./second-path.css"] | ||
}) | ||
).rejects.toThrow( | ||
"The --print-config option must be used with exactly one file path." | ||
); | ||
}); | ||
|
||
it("printConfig with globs should throw", () => { | ||
expect( | ||
printConfig({ | ||
files: ["./*.css"] | ||
}) | ||
).rejects.toThrow("The --print-config option does not support globs."); | ||
}); |
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,54 @@ | ||
/* @flow */ | ||
"use strict"; | ||
|
||
const _ = require("lodash"); | ||
const createStylelint = require("./createStylelint"); | ||
const globby /*: Function*/ = require("globby"); | ||
const path = require("path"); | ||
|
||
module.exports = function( | ||
options /*: stylelint$standaloneOptions */ | ||
) /*: Promise<stylelint$config>*/ { | ||
const code = options.code; | ||
const config = options.config; | ||
const configBasedir = options.configBasedir; | ||
const configFile = options.configFile; | ||
const configOverrides = options.configOverrides; | ||
const globbyOptions = options.globbyOptions; | ||
const files = options.files; | ||
|
||
const isCodeNotFile = code !== undefined; | ||
if (!files || files.length !== 1 || isCodeNotFile) { | ||
return Promise.reject( | ||
new Error( | ||
"The --print-config option must be used with exactly one file path." | ||
) | ||
); | ||
} | ||
|
||
const filePath = files[0]; | ||
|
||
if (globby.hasMagic(filePath)) { | ||
return Promise.reject( | ||
new Error("The --print-config option does not support globs.") | ||
); | ||
} | ||
|
||
const stylelint = createStylelint({ | ||
config, | ||
configFile, | ||
configBasedir, | ||
configOverrides | ||
}); | ||
|
||
const cwd = _.get(globbyOptions, "cwd", process.cwd()); | ||
const absoluteFilePath = !path.isAbsolute(filePath) | ||
? path.join(cwd, filePath) | ||
: path.normalize(filePath); | ||
|
||
const configSearchPath = stylelint._options.configFile || absoluteFilePath; | ||
|
||
return stylelint | ||
.getConfigForFile(configSearchPath) | ||
.then(result => result.config); | ||
}; |
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,5 @@ | ||
{ | ||
"rules": { | ||
"block-no-empty": true | ||
} | ||
} |
Empty file.