I've got a few snippets set up and working as I would like to, but I'm having a hard time getting one snippet to work where I believe I will need to have multiple transforms occur?
Essentially I have a TypeScript Interface defined for one of my components.
i.e. IRadioButtonListProps.ts which is inside of an Interfaces folder. The Interfaces folder has a sibling folder named Theme containing an interface named IRadioButtonListTheme.ts
Inside of IRadioButtonListProps I'm trying to stub out the entire interface. The snippet I currently have stubs out the interface like...
import * as React from 'react';
import IRadioButtonListPropsTheme from '../Theme/IRadioButtonListPropsTheme';
export interface IRadioButtonListPropsProps {
...props...
}
export default IRadioButtonListPropsProps;
The import line inside of the snippet is...
"import I${TM_FILENAME_BASE/(.*)\\..+$/1ドル/}Props from './Interfaces/I${TM_FILENAME_BASE/(.*)\\..+$/1ドル/}Props';"
What I'm trying to have happen and can't seem to figure out is how to also remove the word "Props". So instead of import IRadioButtonListPropsTheme... I would get import import IRadioButtonListTheme....
At the same time, I want to remove all extensions, including those of the form *.abc.abc ("two" extensions) and *.abc (one simple extension).
Is this possible?
1 Answer 1
It isn't crystal clear what you what but try:
"import ${TM_FILENAME/((\\w*)Props)*?(\\..*)/2ドル/}Theme from './Interfaces/${TM_FILENAME/((\\w*)Props)*?(\\..*)/2ドル/}Theme';"
which results in:
import IRadioButtonListTheme from './Interfaces/IRadioButtonListTheme';
from IRadioButtonListProps.ts
and
import CheckboxListTheme from './Interfaces/CheckboxListTheme';
from CheckboxListProps.test.tsx
[Edit] Here is a simpler version which I think also works:
"import ${TM_FILENAME/(Props)*?(\\..*)//}Theme from './Interfaces/${TM_FILENAME/(Props)*?(\\..*)//}Theme';"
- match any "Props", if any, replace with nothing.
- match from first \. to end of filename, replace with nothing.
7 Comments
Props, but stopped ensuring that there wasn't an extension. Some of the snippets are used on test files named similar to CheckboxList.test.tsx. I was using the TM_FILENAME_BASE to remove the .tsx and then the existing transform to remove .testCheckboxList.test.tsx and CheckboxListProps.test.tsx should both produce CheckboxList (as far as the transform is concerned).TM_DIRECTORY? i.e. c:\a\b\c\d\e would produce e
(.*)\\..+$supposed to match?(.*)\\..+$to(.*?)(?:Props)?\\.[^.]+$