wavebeem / jsx-info Goto Github PK
View Code? Open in Web Editor NEWDisplays a report of JSX component and prop usage
License: MIT License
Displays a report of JSX component and prop usage
License: MIT License
I'm using this package with jest to check that all used strings by react-intl
are in file with localization.
So, I'm using this package to find all <FormattedMessage id="..." defaultMessage="...">
component usage, extract it by id
and compare that this id
is exist in all localized files.
Unfortunately, analyze()
method doesn't include prop values and almost methods are private, so I'm using too dirty way to use your package with rewire
package :)
// All methods are private, so rewire is needed to access into them
const jsxInfoApi = rewire('jsx-info/dist/src/api');
const parseJsxInfo = jsxInfoApi.__get__('parse');
const createPropJsxInfo = jsxInfoApi.__get__('createProp');
...
const filenames = await globby([
'containers/**/*.jsx',
'components/**/*.jsx',
'mappings.jsx',
], {
absolute: true,
onlyFiles: true,
gitignore: true,
ignore: [],
cwd: directory,
});
filenames.forEach((filename) => {
try {
const code = fs.readFileSync(path.resolve(directory, filename), 'utf8');
parseJsxInfo(code, {
babelPlugins: [],
typescript: filename.endsWith('.tsx') || filename.endsWith('.ts'),
onlyComponents: [
'FormattedMessage',
'CustomHeadingComponent',
'FormRow',
'DataRow',
'InfoRow',
],
onComponent: ({ node }) => {
node.openingElement.attributes.forEach((propNode) => {
const propValue = propNode.value.value;
const propName = createPropJsxInfo(propNode);
// ... here propName is validated and propValue is used
});
},
});
} catch (error) {
throw error;
}
});
It covers 99% of my cases, except variables.
What do you think is better?
analyze()
method to include prop values as well? It might be good, but how to deal with non-string props?Thanks for this awesome package!
It's annoying to have to re-issue command line arguments. The current solution of storing options inside an npm script and using npm run jsx-info
instead of npx jsx-info
just isn't as nice.
Let's use cosmiconfig to load a configuuration file.
For example npx jsx-info --component Link
would output the usage of component only
There should be a mode like --mode lines
or something that shows filename and line numbers (ideally in a format that vscode lets you cmd-click) along with context, so you can see WHERE and HOW each prop i used for a given component
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.