-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enforce qualifier in action names
BREAKING CHANGE: This ensures every action has name of the form `[qualifier] action name`. See the [new doc](https://github.com/ardoq/rxbeach/blob/master/docs/qualified-action-names.md) for how to automate this process.
- Loading branch information
Showing
6 changed files
with
81 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Converting to qualified action names | ||
======================== | ||
|
||
With the introduced requirment that action names have to be of the form | ||
`[qualifier] action name`, it might be useful to automate this change. | ||
|
||
In Ardoq we used this codemod to convert 600 actions. It picks the name of the | ||
file (or folder if the file is called `actions` or `utils`) and uses that as the | ||
qualifier. It can be run with [jscodeshift](https://github.com/facebook/jscodeshift/): | ||
|
||
npx jscodeshift --parser ts --extension ts -t codemod-qualified-actions.js src/js/ardoq | ||
|
||
|
||
```javascript | ||
function qualified(path, action) { | ||
const parts = path.split('.')[0].split('/'); | ||
let name = parts[parts.length - 1]; | ||
if (name === 'actions' || name === 'utils') { | ||
name = parts[parts.length - 2]; | ||
} | ||
return `[${name}] ${action}`; | ||
} | ||
|
||
module.exports = function ({ source, path }, api, options) { | ||
return api | ||
.jscodeshift(source) | ||
.find(api.jscodeshift.CallExpression, { | ||
callee: { | ||
type: 'Identifier', | ||
name: 'actionCreator', | ||
}, | ||
}) | ||
.filter(n => { | ||
const arg = n.value.arguments[0]; | ||
return arg && arg.type === 'StringLiteral' && !arg.value.startsWith('['); | ||
}) | ||
.forEach(n => { | ||
n.value.arguments[0].value = qualified(path, n.value.arguments[0].value); | ||
}) | ||
.toSource(); | ||
}; | ||
``` |
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