LiveTemplate - file name without extension

I want to create a live template for test files that have name like "SomeComponent.spec.jsx", where the component being tested is automatically imported, e.g.

 

import './$FILENAME$.jsx';

 

The filenameWithoutExtension function doesn't work here as it only strips the last extension, leaving me with "SomeComponent.spec". I tried a few combinations of other functions but couldn't find anything that worked. The groovy one looked promising until I ran into the same problem as this: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000759284-WebStorm-Live-Templates-variables-groovyScript-groovy-code-not-working- 

 

Is there a way of getting the filename without any extension in this case with the existing (working!) webstorm live template functions?

1
5 comments

I did this using regularExpression:

regularExpression(fileNameWithoutExtension(), ".spec$", "")
1

Hi there,

Have you thought about calling that "filenameWithoutExtension function" again? Something like this (or whatever the right syntax is):

filenameWithoutExtension(filenameWithoutExtension(FILENAME))
0
Avatar
Permanently deleted user

Ooo, nice idea, hadn't thought of that! Sadly it doesn't seem to work - I still get "SomeComponent.spec" as the value - I suspect that fileNameWithoutExtension ignores any arguments I give it and just returns the value based off the current filename, so nesting it has no effect

0

I had the same problem. I decided to use just a simple variable and use the autocomplete function to suggest the filename for me.

0

You can use

substringBefore(fileName(),".")
0

Please sign in to leave a comment.