-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: redput: add ability to pass options
- Loading branch information
1 parent
fcfcd47
commit daae14d
Showing
11 changed files
with
96 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import tryCatch from 'try-catch'; | ||
|
||
const {parse} = JSON; | ||
|
||
export const parsePlugin = (raw) => { | ||
const [comment, ...lines] = raw.split('\n'); | ||
const name = comment | ||
.replace('//', '') | ||
.trimStart(); | ||
const [options, name] = parseComment(comment); | ||
|
||
return { | ||
name, | ||
lines, | ||
options, | ||
}; | ||
}; | ||
|
||
function parseComment(comment) { | ||
const raw = comment | ||
.replace('//', '') | ||
.trimStart(); | ||
|
||
const [error, data] = tryCatch(parse, raw); | ||
|
||
if (error) | ||
return ['', raw]; | ||
|
||
return [data[0], data[1]]; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
lib/write/nested/add-rule/plugin-insert-get-rule/fixture/off-fix.js
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,8 @@ | ||
const getRule = (a) => ({ | ||
[a]: require(`./${a}`), | ||
}); | ||
|
||
module.exports.rules = { | ||
...getRule('add-function', 'off'), | ||
...getRule('hello', 'off'), | ||
}; |
7 changes: 7 additions & 0 deletions
7
lib/write/nested/add-rule/plugin-insert-get-rule/fixture/off.js
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,7 @@ | ||
const getRule = (a) => ({ | ||
[a]: require(`./${a}`), | ||
}); | ||
|
||
module.exports.rules = { | ||
...getRule('add-function', 'off'), | ||
}; |
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