-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
feat/issue-1398: added support for custom configuration #1401
Open
RohitLuthra19
wants to merge
15
commits into
lint-staged:master
Choose a base branch
from
RohitLuthra19:feat/issue-1398
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c55b291
feat/issue-1398: added support for custom configuration
2626c43
feat: added check to proceed only with not null/undefined
da2ede0
feat: added check to proceed only if is Function
64c1382
feat/issue-1398: updated the condition to return the errors early
e769fd3
feat/issue-1398: removed command field from object requirement
0682aff
feat/issue-1398: refactored makeCmdTasks function and added unit test…
eb8dd33
v15.2.3
f27d888
chore(changeset): release
6d82f42
Revert "v15.2.3"
20c3f86
feat: removed version related changes from package.json
e1b2071
Merge branch 'lint-staged:master' into feat/issue-1398
RohitLuthra19 d3f72e0
feat: updated the logic to accept the object task
907afa5
feat: added changeset
94eb304
feat: updated the logic to accept the object task
de37e43
Merge branch 'master' into feat/issue-1398
RohitLuthra19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'lint-staged': minor | ||
--- | ||
|
||
added support for custom configuration |
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,40 @@ | ||
import debug from 'debug' | ||
|
||
const debugLog = debug('lint-staged:customTask') | ||
|
||
import { configurationError } from './messages.js' | ||
import { makeErr } from './resolveTaskFn.js' | ||
import { getInitialState } from './state.js' | ||
|
||
/** | ||
* Handles function configuration and pushes the tasks into the task array | ||
* | ||
* @param {object} command | ||
* @param {Array<string>} files | ||
* @param {Array} cmdTasks | ||
* @throws {Error} If the function configuration is not valid | ||
*/ | ||
export const handleCustomConfig = (command, files, cmdTasks) => { | ||
debugLog('Handling custom task %o', command) | ||
if (typeof command.title === 'string' && typeof command.task === 'function') { | ||
const task = async (ctx = getInitialState()) => { | ||
try { | ||
await command.task(files, ctx) | ||
} catch (e) { | ||
throw makeErr(command.title, e, ctx) | ||
} | ||
} | ||
cmdTasks.push({ | ||
title: command.title, | ||
task, | ||
}) | ||
} else { | ||
throw new Error( | ||
configurationError( | ||
'[Function]', | ||
'Function task should contain `title` and `task` where `title` should be string and `task` should be function.', | ||
command | ||
) | ||
) | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has started to become a bit complex... I wonder if we could split it somehow, maybe different handling for function and regular config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done