From bb37c686e73df6560f8cc7ec7a1a5c83b128d4bc Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 29 Aug 2019 01:24:40 +0200 Subject: [PATCH] feat: allow to pass config instead of configPath --- README.md | 16 +++++++++++++++- src/index.js | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1dadfc6a6..eecb2d650 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Linter commands work on a subset of all staged files, defined by a _glob pattern * **`"!(*test).js"`**. will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js` * If the glob pattern does contain a slash (`/`), it will match for paths as well: * **`"/*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js` - * **`"foo/**/\*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js` + * **`"foo/**/*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js` When matching, `lint-staged` will do the following @@ -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. diff --git a/src/index.js b/src/index.js index 759e1c535..15334dc23 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -52,12 +53,12 @@ function loadConfig(configPath) { * @returns {Promise} 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