Skip to content

Commit

Permalink
Fix misc lint errors (decred#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
StabbarN authored and alexlyp committed Jan 23, 2018
1 parent d0c7a00 commit 621fd44
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "cross-env NODE_ENV=test jest",
"test-watch": "npm test -- --watch",
"test-e2e": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --retries 2 --compilers js:babel-register --require ./test/setup.js ./test/e2e.js",
"lint": "./node_modules/.bin/eslint --ignore-path .eslintignore *.js app && ./node_modules/.bin/stylelint app/style/*.less",
"lint": "./node_modules/.bin/eslint --ignore-path .eslintignore *.js app scripts && ./node_modules/.bin/stylelint app/style/*.less",
"lint-fix": "npm run lint -- --fix && ./node_modules/.bin/stylelint app/style/*.less",
"hot-server": "cross-env NODE_ENV=development node --max_old_space_size=4096 -r babel-register server.js",
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.electron.js --progress --profile --colors",
Expand Down
100 changes: 50 additions & 50 deletions scripts/aliasDefaultMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,82 @@
*
*/
const COMPONENT_NAMES = [
'FormattedMessage',
"FormattedMessage",
];

const DESCRIPTOR_PROPS = new Set(['m']);
const DESCRIPTOR_PROPS = new Set(["m"]);

function aliasDefaultMessagePlugin({types: t}) {

function referencesImport(path, mod, importedNames) {
if (!(path.isIdentifier() || path.isJSXIdentifier())) {
return false;
}

return importedNames.some((name) => path.referencesImport(mod, name));
function referencesImport(path, mod, importedNames) {
if (!(path.isIdentifier() || path.isJSXIdentifier())) {
return false;
}

function getModuleSourceName(opts) {
return opts.moduleSourceName || 'react-intl';
}
return importedNames.some((name) => path.referencesImport(mod, name));
}

function evaluatePath(path) {
const evaluated = path.evaluate();
if (evaluated.confident) {
return evaluated.value;
}
function getModuleSourceName(opts) {
return opts.moduleSourceName || "react-intl";
}

throw path.buildCodeFrameError(
'[React Intl] Messages must be statically evaluate-able for extraction.'
);
function evaluatePath(path) {
const evaluated = path.evaluate();
if (evaluated.confident) {
return evaluated.value;
}

function getMessageDescriptorKey(path) {
if (path.isIdentifier() || path.isJSXIdentifier()) {
return path.node.name;
}
throw path.buildCodeFrameError(
"[React Intl] Messages must be statically evaluate-able for extraction."
);
}

return evaluatePath(path);
function getMessageDescriptorKey(path) {
if (path.isIdentifier() || path.isJSXIdentifier()) {
return path.node.name;
}

function createMessageDescriptor(propPaths) {
return propPaths.reduce((hash, [keyPath, valuePath]) => {
const key = getMessageDescriptorKey(keyPath);
return evaluatePath(path);
}

if (DESCRIPTOR_PROPS.has(key)) {
hash[key] = keyPath;
}
function createMessageDescriptor(propPaths) {
return propPaths.reduce((hash, [keyPath]) => {
const key = getMessageDescriptorKey(keyPath);

return hash;
}, {});
}
if (DESCRIPTOR_PROPS.has(key)) {
hash[key] = keyPath;
}

return hash;
}, {});
}

return {
visitor: {
JSXOpeningElement(path, state) {
const {file, opts} = state;
const moduleSourceName = getModuleSourceName(opts);
const name = path.get('name');
return {
visitor: {
JSXOpeningElement(path, state) {
const {opts} = state;
const moduleSourceName = getModuleSourceName(opts);
const name = path.get("name");

if (referencesImport(name, moduleSourceName, COMPONENT_NAMES)) {
const attributes = path.get('attributes')
if (referencesImport(name, moduleSourceName, COMPONENT_NAMES)) {
const attributes = path.get("attributes")
.filter((attr) => attr.isJSXAttribute());

let descriptor = createMessageDescriptor(
let descriptor = createMessageDescriptor(
attributes.map((attr) => [
attr.get('name'),
attr.get('value'),
attr.get("name"),
attr.get("value"),
])
);

if (descriptor.m) {
descriptor.m.replaceWith(t.JSXIdentifier("defaultMessage"));
}
}

}
if (descriptor.m) {
descriptor.m.replaceWith(t.JSXIdentifier("defaultMessage"));
}
}

}
}
};
}

module.exports = aliasDefaultMessagePlugin;
2 changes: 1 addition & 1 deletion scripts/prepareUntranslated.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// translationRunner.js
const manageTranslations = require('react-intl-translations-manager').default;
const manageTranslations = require("react-intl-translations-manager").default;

manageTranslations({
messagesDirectory: "app/i18n/extracted",
Expand Down

0 comments on commit 621fd44

Please sign in to comment.