Derive name for `const` and `forEach` from expression
See original GitHub issueHey! I have awesome idea to derive variable names for builtin const
and forEach
snippets.
const
Improve variable name for const
, let
(and var
?) snippets.
I simply use regexs to derive const name from expression.
We can use the part after get|read|create|retrieve|select|modify|update|use
Some examples:
someObject.getUser().const ; const user = someObject.getUser()
// react or vue
useRouter().const ; const router = useRouter()
fs.readFile().const ; const file = fs.readFile()
await updateRect(...anyArgs).const ; const rect = await updateRect(...anyArgs)
UPDATE: special handling of expression starting with new
:
- just lowercase variable (if class starts with uppercase)
const mutationObserver = new MutationObserver().const
forEach
Also for
forof
snippet.
Just use singular form of last part of expression (if appliable).
- Skip if identifier doesn’t end with
s
orsList
(or justList
?) - Remove
List
part if appliable - Use pluralize with count
1
to get singular form
Example:
cookies.forEach(cookie => )
I’m using it for a while and can say its pretty neat.
Anyway I think it’s much better than just name
or item
variables that should be renamed in 99% cases.
What do you think? Should we make this behaviour disableable?
Issue Analytics
- State:
- Created a year ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
constant declarations with forEach loop - javascript
Why is my hard drive still working long after I finished the file transfer? What is the meaning of the equestrian term “Undermounted”?...
Read more >for...of - JavaScript | MDN - MDN Web Docs
Receives a value from the sequence on each iteration. May be either a declaration with const , let , or var , or...
Read more >Guide to JavaScript's forEach() Method - Stack Abuse
In this guide, learn everything you need to know about JavaScript's forEach() Method - loop through array, set or map, sum elements or...
Read more >Which is faster: for, for…of, or forEach loops in JavaScript
The JavaScript for loop iterates the elements for the fixed number of times. It should be used if the number of iteration is...
Read more >for..in versus for..of Loops - bitsofcode
The for..in method provides us the most straightforward way to loop over Object keys and values, since Objects do not have access to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re right! I’d make it work in the web, reduce ext size (and probably parsing time, as it’d reuse sourcefiles). I think I’m going to give more details in https://github.com/ipatalas/vscode-postfix-ts/issues/13 within a few days.
Of course! You can look at repository URL. I’m using it on daily bases (also that’s why I don’t use webstorm anymore).
Actually I don’t have plugin published, because for now it’s not possible to install it in some workspace, because it relies on the extension itself. This is primarily a VSCode extension, that as you said you install only once.
No, its just disabled by default:
"editor.suggest.preview": true