Skip to content

tsx: less restrictive var matching#10

Merged
stefanhengl merged 1 commit intomainfrom
sh/less-restrictive-var-matching
Jan 11, 2023
Merged

tsx: less restrictive var matching#10
stefanhengl merged 1 commit intomainfrom
sh/less-restrictive-var-matching

Conversation

@stefanhengl
Copy link
Member

Relates to https://github.com/sourcegraph/sourcegraph/issues/45800

With the current rules we don't recognize isActive in

let isActive = a === b

because it is neither exported

--regex-tsx=/^[ \t]*export[ \t]+(var|let|const)[ \t]+([a-zA-Z0-9_$]+)/\2/v,variable/2

nor is it an anonymous function

--regex-tsx=/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_$]+)[ \t]*=[ \t]*function[ \t]*[*]?[ \t]*\(\)/\2/v,variable/

I am not sure about the motivation to exclude local vars. Maybe the intent was to limit the size of the tag files?

Replacing the latter rule with the following, more liberal one captures both, anonymous functions and unexported variables.

--regex-tsx=/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_$]+)/\2/v,variable/

Test plan

with App.tsx

universal-ctags --langdef=tsx --langmap=tsx:.tsx --regex-tsx="/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_$]+)/\2/v,variable/" -f - App.tsx
brand   App.tsx /^  let brand = searchParams.get("brand");$/;"  v
isActive        App.tsx /^  let isActive = searchParams.get("brand") === brand;$/;"     v
name    App.tsx /^          let name = `${snkr.brand} ${snkr.model} ${snkr.colorway}`;$/;"      v
name    App.tsx /^  let name = `${snkr.brand} ${snkr.model} ${snkr.colorway}`;$/;"      v
sneakers        App.tsx /^  const sneakers = React.useMemo(() => {$/;"  v
snkr    App.tsx /^  let snkr = getSneakerById(id);$/;"  v

Relates to https://github.com/sourcegraph/sourcegraph/issues/45800

With the current rules we don't recognize `isActive` in

```
...
let isActive = a === b
...
```

because it is neither exported
```
--regex-tsx=/^[ \t]*export[ \t]+(var|let|const)[ \t]+([a-zA-Z0-9_$]+)/\2/v,variable/2
```

nor is it an anonymous function
```
--regex-tsx=/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_$]+)[ \t]*=[ \t]*function[ \t]*[*]?[ \t]*\(\)/\2/v,variable/
```

Replacing the latter rule with this more liberal one captures both,
anonymous functions and unexported variables.

```
--regex-tsx=/^[ \t]*(var|let|const)[ \t]+([a-zA-Z0-9_$]+)/\2/v,variable/

```
@stefanhengl stefanhengl merged commit c27675d into main Jan 11, 2023
@keegancsmith keegancsmith deleted the sh/less-restrictive-var-matching branch January 11, 2023 18:13
Kvarnefalk pushed a commit to Kvarnefalk/go-ctags that referenced this pull request Sep 28, 2023
Relates to https://github.com/sourcegraph/sourcegraph/issues/45800

With the current rules we don't recognise local vars in typescript. This PR
changes an existing rule to be less restrictive to include local vars, too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants