Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass config instead of configPath #695

Merged
merged 1 commit into from Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -400,6 +400,20 @@ const success = await lintStaged({
})
```

You can also pass config directly with `config` option:


```js
const success = await lintStaged({
config: {
'*.js': 'eslint --fix'
},
shell: false,
quiet: false,
debug: false
})
```

### Using with JetBrains IDEs _(WebStorm, PyCharm, IntelliJ IDEA, RubyMine, etc.)_

_**Update**_: The latest version of JetBrains IDEs now support running hooks as you would expect.
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Expand Up @@ -43,6 +43,7 @@ function loadConfig(configPath) {
*
* @param {object} options
* @param {string} [options.configPath] - Path to configuration file
* @param {object} [options.config] - Object with configuration for programmatic API
* @param {boolean} [options.relative] - Pass relative filepaths to tasks
* @param {boolean} [options.shell] - Skip parsing of tasks for better shell support
* @param {boolean} [options.quiet] - Disable lint-staged’s own console output
Expand All @@ -52,12 +53,12 @@ function loadConfig(configPath) {
* @returns {Promise<boolean>} Promise of whether the linting passed or failed
*/
module.exports = function lintStaged(
{ configPath, relative = false, shell = false, quiet = false, debug = false } = {},
{ configPath, config, relative = false, shell = false, quiet = false, debug = false } = {},
logger = console
) {
debugLog('Loading config using `cosmiconfig`')

return loadConfig(configPath)
return (config ? Promise.resolve({ config, filepath: '(input)' }) : loadConfig(configPath))
.then(result => {
if (result == null) throw errConfigNotFound

Expand Down