Skip to content

Commit

Permalink
Chore/lint react tokens (patternfly#3725)
Browse files Browse the repository at this point in the history
* updated package.json lint:ts

* chore(react-tokens): resolved linter errors

* resolved PR feedback

* reverted function order as rule was removed
  • Loading branch information
evwilkin authored Feb 17, 2020
1 parent c6d2511 commit 81879c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"generate": "yarn plop",
"lint:md": "yarn eslint packages/patternfly-4 --ext md --no-eslintrc --config .eslintrc-md.json --cache",
"lint:style": "stylelint \"**/sass/**/*.scss\" \"!**/dist/**/*.scss\"",
"lint:ts": "node --max-old-space-size=4096 node_modules/.bin/eslint packages/patternfly-4/react-core packages/patternfly-4/react-table packages/patternfly-4/react-topology packages/patternfly-4/react-catalog-view-extension packages/patternfly-4/react-docs packages/patternfly-4/react-inline-edit-extension packages/patternfly-4/react-charts packages/patternfly-4/react-integration packages/patternfly-4/react-styled-system packages/patternfly-4/react-styles --ext js,jsx,ts,tsx --cache",
"lint:ts": "node --max-old-space-size=4096 node_modules/.bin/eslint packages/patternfly-4/react-core packages/patternfly-4/react-table packages/patternfly-4/react-topology packages/patternfly-4/react-catalog-view-extension packages/patternfly-4/react-docs packages/patternfly-4/react-inline-edit-extension packages/patternfly-4/react-charts packages/patternfly-4/react-integration packages/patternfly-4/react-styled-system packages/patternfly-4/react-styles packages/patternfly-4/react-tokens --ext js,jsx,ts,tsx --cache",
"lint:versions": "node ./packages/patternfly-4/verifyCoreVersions.js",
"prettier": "node node_modules/.bin/prettier --write \"storybook/**/*.{js,ts,tsx}\" \"packages/**/*.{js,ts,tsx}\" \"scripts/**/*.{js,ts,tsx}\"",
"serve:docs": "lerna run serve",
Expand Down
8 changes: 5 additions & 3 deletions packages/patternfly-4/react-tokens/src/generateTokens.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable global-require,import/no-dynamic-require,no-restricted-globals */
const glob = require('glob');
const { dirname, resolve, join } = require('path');
const { parse } = require('css');
Expand Down Expand Up @@ -52,6 +51,9 @@ readdirSync(templateDir).forEach(templateFile => {
const template = require(join(templateDir, templateFile));
outputFileSync(template.getOutputPath({ outDir }), template.getContent({ tokens }));
Object.entries(tokens).forEach(([tokenName, tokenValue]) => {
outputFileSync(template.getSingleOutputPath({ outDir, tokenName }), template.getSingleContent({ tokenName, tokenValue }));
})
outputFileSync(
template.getSingleOutputPath({ outDir, tokenName }),
template.getSingleContent({ tokenName, tokenValue })
);
});
});
3 changes: 3 additions & 0 deletions packages/patternfly-4/react-tokens/src/generateTokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test('keeps variable reference if computing fails', () => {
expect(getOutputs()).toMatchSnapshot();
});

/**
*
*/
function getOutputs() {
return outputFileSyncMock.mock.calls.reduce((acc, call) => {
const [filePath, content] = call;
Expand Down
5 changes: 3 additions & 2 deletions packages/patternfly-4/react-tokens/src/templates/d.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
}, ''),
getSingleOutputPath: ({ outDir, tokenName }) => join(outDir, `js/${tokenName}.d.ts`),
getSingleContent: ({ tokenName, tokenValue }) =>
`const ${tokenName}: {${Object.entries(tokenValue).map(([key, value]) =>
`${JSON.stringify(key)}: ${JSON.stringify(value)};`).join(' ')}}\nexport default ${tokenName}\n`
`const ${tokenName}: {${Object.entries(tokenValue)
.map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)};`)
.join(' ')}}\nexport default ${tokenName}\n`
};
1 change: 0 additions & 1 deletion packages/patternfly-4/react-tokens/src/templates/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ module.exports = {
getSingleOutputPath: ({ outDir, tokenName }) => join(outDir, `esm/${tokenName}.js`),
getSingleContent: ({ tokenValue }) => `export default ${JSON.stringify(tokenValue)}\n`
};

0 comments on commit 81879c8

Please sign in to comment.