question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive in macrosRegex

See original GitHub issue

We recently released @formatjs/macro and got this issue https://github.com/formatjs/react-intl/issues/1511 for a user. The macro we use is not compatible with babel-plugin-macros because we use that in TS transformer & eslint as well so we don’t wrap it, but it looks like babel-plugin-macros might be too aggressive and throw an error if it detects anything that looks like macrosRegex. My suggestion: Can we turn this into a warning?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
AndyOGocommented, Dec 9, 2019

Alright, to whom it may concerns.

We had to extend our Babel config to supply a custom isMacrosName() function. https://github.com/kentcdodds/babel-plugin-macros/blob/2cac571a5809c42671c2bcbd74921df65036369e/src/index.js#L5-L6

babel.config.js:

// Fixes https://github.com/formatjs/react-intl/issues/1511
//       https://github.com/kentcdodds/babel-plugin-macros/issues/131
const macrosRegex = /[./]macro(\.js)?$/;
const testMacrosRegex = v =>
  macrosRegex.test(v) && v.indexOf('@formatjs/macro') === -1;
module.exports = {
  plugins: [
    [
      'macros',
      {
        isMacrosName: testMacrosRegex,
      },
    ],
  ],
};
2reactions
AndyOGocommented, Dec 9, 2019

@kentcdodds I couldn’t find any documentation for isMacrosName(), neither in user docs, nor author docs. https://github.com/kentcdodds/babel-plugin-macros/search?q=isMacrosName&unscoped_q=isMacrosName

I face the same warning from @formatjs/macro as described here https://github.com/formatjs/react-intl/issues/1511

Here is the reuslt of npm ls:

@axa-ch/aletheia@1.21.9 git-repos\aletheia
+-- babel-plugin-macros@2.8.0
+-- babel-plugin-react-intl@5.1.11
+-- import-all.macro@2.0.3
| `-- babel-plugin-macros@2.8.0  deduped
`-- react-intl@3.9.1

Error Log:

FAIL  src/components/wizard/Wizard.test.js
  ● Test suite failed to run
    git-repos\aletheia\node_modules\react-intl\dist\index.js: The macro imported from "@formatjs/macro" must be wrapped in "createMacro" which you can get from "babel-plugin-macros". Please refer to the documentation to see how to do this properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/author.md#writing-a-macro
      at applyMacros (node_modules/babel-plugin-macros/dist/index.js:211:11)
      at node_modules/babel-plugin-macros/dist/index.js:153:30
          at Array.forEach (<anonymous>)
      at VariableDeclaration (node_modules/babel-plugin-macros/dist/index.js:143:55)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:55:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:42:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:90:31)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:112:16)
      at TraversalContext.visitMultiple (node_modules/@babel/traverse/lib/context.js:79:17)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:138:19)
Read more comments on GitHub >

github_iconTop Results From Across the Web

regex_macro false positive · Issue #2586 · rust-lang/rust-clippy ...
When defining a custom regex! macro to use the lazy_static pattern more easily, the regex_macro picks it up. This occurs with nom and...
Read more >
handling false positives regex - Stack Overflow
I have a regex responsible for matching tracking numbers for USPS. There are 2 expressions grouped together as follows:
Read more >
IT14093: FULL TEXT MACRO REGEX FILTERS INCORRECT ...
We would rather have a known false positive than a known false negative. As such, we will keep the dashes as they are....
Read more >
A Type System for Regular Expressions - Amazon S3
routines are recognized by the Regex Checker and cause it to be more precise in its type analysis by avoiding false positives.
Read more >
Suppression of false positive warnings - PVS-Studio
Suppressing false positives located within C/C++ macro statements (#define) and for other code fragments. It goes without saying that the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found