Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #72 from panter/fixes/deps-security-issues-again
Browse files Browse the repository at this point in the history
style(eslint): update eslint and use prettier
  • Loading branch information
claudiocro authored Jun 12, 2019
2 parents 61dbf32 + 1074378 commit f454fc2
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 512 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"window": true,
"__VERSION__": true
},
"plugins": [],
"extends": ["airbnb"],
"plugins": ["prettier"],
"extends": ["airbnb", "prettier"],
"rules": {
"prettier/prettier": ["error", { "singleQuote": true }],
"arrow-body-style": [1, "as-needed"],
"no-underscore-dangle": 0,
"react/prop-types": 0,
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/preset-stage-2": "^7.0.0",
"@semantic-release/commit-analyzer": "^6.1.0",
"@semantic-release/error": "^2.2.0",
"@semantic-release/github": "^5.2.10",
"@semantic-release/npm": "^5.1.7",
"@semantic-release/release-notes-generator": "^7.1.4",
"@types/i18next": "^8.4.3",
"@vuepress/plugin-pwa": "^1.0.1",
"@vuepress/theme-vue": "^1.0.1",
Expand All @@ -65,11 +60,13 @@
"chai": "^3.5.0",
"coveralls": "^3.0.4",
"cross-env": "^3.0.0",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.13.0",
"gh-pages": "^1.0.0",
"i18next": "^6.0.1",
"jasmine": "^2.5.3",
Expand Down
27 changes: 18 additions & 9 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ export default {
props: {
tag: {
type: String,
default: 'span',
default: 'span'
},
path: {
type: String,
required: true,
required: true
},
options: {
type: Object,
},
type: Object
}
},
render(h, { props, data, children, parent }) {
const i18next = parent.$i18n;
if (!i18next) {
return h(props.tag, data, children);
}

const path = props.path;
const { path } = props;
const options = props.options || {};

const REGEXP = i18next.i18next.services.interpolator.regexp;
const format = i18next.t(path, { ...options, interpolation: { prefix: '#$?', suffix: '?$#' } });
const format = i18next.t(path, {
...options,
interpolation: { prefix: '#$?', suffix: '?$#' }
});
const tchildren = [];

format.split(REGEXP).reduce((memo, match, index) => {
Expand All @@ -35,9 +38,15 @@ export default {
child = match;
} else {
const place = match.trim();
// eslint-disable-next-line no-restricted-globals
if (isNaN(parseFloat(place)) || !isFinite(place)) {
children.forEach((e) => {
if (!child && e.data.attrs && e.data.attrs.place && e.data.attrs.place === place) {
children.forEach(e => {
if (
!child &&
e.data.attrs &&
e.data.attrs.place &&
e.data.attrs.place === place
) {
child = e;
}
});
Expand All @@ -51,5 +60,5 @@ export default {
}, tchildren);

return h(props.tag, data, tchildren);
},
}
};
16 changes: 9 additions & 7 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function equalLanguage(el, vnode) {
function equalValue(value, oldValue) {
if (value === oldValue) {
return true;
} else if (value && oldValue) {
}
if (value && oldValue) {
return (
value.path === oldValue.path &&
value.language === oldValue.language &&
Expand Down Expand Up @@ -38,16 +39,14 @@ function parseValue(value) {
if (typeof value === 'string') {
path = value;
} else if (toString.call(value) === '[object Object]') {
path = value.path;
language = value.language;
args = value.args;
({ path, language, args } = value);
}

return { path, language, args };
}

function t(el, binding, vnode) {
const value = binding.value;
const { value } = binding;

const { path, language, args } = parseValue(value);
if (!path && !language && !args) {
Expand All @@ -66,7 +65,10 @@ function t(el, binding, vnode) {
}

const vm = vnode.context;
el.textContent = vm.$i18n.i18next.t(path, { ...(language ? { lng: language } : {}), ...args });
el.textContent = vm.$i18n.i18next.t(path, {
...(language ? { lng: language } : {}),
...args
});

el._i18nLanguage = vm.$i18n.i18next.language;
}
Expand All @@ -89,5 +91,5 @@ export function update(el, binding, vnode, oldVNode) {

export default {
bind,
update,
update
};
5 changes: 3 additions & 2 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class VueI18n {
bindI18n: 'languageChanged loaded',
bindStore: 'added removed',
loadComponentNamespace: false,
...opts,
...opts
};

this._vm = null;
Expand All @@ -27,7 +27,7 @@ export default class VueI18n {

resetVM(data) {
const oldVM = this._vm;
const silent = Vue.config.silent;
const { silent } = Vue.config;
Vue.config.silent = true;
this._vm = new Vue({ data });
Vue.config.silent = silent;
Expand All @@ -39,6 +39,7 @@ export default class VueI18n {
get i18nLoadedAt() {
return this._vm.$data.i18nLoadedAt;
}

set i18nLoadedAt(date) {
this._vm.$set(this._vm, 'i18nLoadedAt', date);
}
Expand Down
42 changes: 22 additions & 20 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ export function install(_Vue) {

Vue = _Vue;

const getByKey = (i18nOptions, i18nextOptions) => (key) => {
const getByKey = (i18nOptions, i18nextOptions) => key => {
if (
i18nOptions &&
i18nOptions.keyPrefix &&
!key.includes(i18nextOptions.nsSeparator)
) {
i18nOptions &&
i18nOptions.keyPrefix &&
!key.includes(i18nextOptions.nsSeparator)
) {
return `${i18nOptions.keyPrefix}.${key}`;
}
return key;
};

const getComponentNamespace = (vm) => {
const getComponentNamespace = vm => {
const namespace = vm.$options.name || vm.$options._componentTag;
if (namespace) {
return {
namespace,
loadNamespace: true,
loadNamespace: true
};
}

return {
namespace: `${Math.random()}`,
namespace: `${Math.random()}`
};
};

Expand All @@ -55,10 +55,10 @@ export function install(_Vue) {
const { namespace, loadNamespace } = getNamespace(this);

if (options.__i18n) {
options.__i18n.forEach((resource) => {
options.__i18n.forEach(resource => {
inlineTranslations = deepmerge(
inlineTranslations,
JSON.parse(resource),
JSON.parse(resource)
);
});
}
Expand All @@ -67,7 +67,7 @@ export function install(_Vue) {
const {
lng = null,
keyPrefix = null,
messages,
messages
} = this.$options.i18nOptions;
let { namespaces } = this.$options.i18nOptions;
namespaces = namespaces || this._i18n.i18next.options.defaultNS;
Expand All @@ -85,7 +85,7 @@ export function install(_Vue) {
this._i18nOptions = { ...options.parent._i18nOptions };
this._i18nOptions.namespaces = [
namespace,
...this._i18nOptions.namespaces,
...this._i18nOptions.namespaces
];
} else if (options.__i18n) {
this._i18nOptions = { namespaces: [namespace] };
Expand All @@ -96,38 +96,40 @@ export function install(_Vue) {
}

const languages = Object.keys(inlineTranslations);
languages.forEach((lang) => {
languages.forEach(lang => {
this._i18n.i18next.addResourceBundle(
lang,
namespace,
{ ...inlineTranslations[lang] },
true,
false,
false
);
});
}

const getKey = getByKey(
this._i18nOptions,
this._i18n ? this._i18n.i18next.options : {},
);
this._i18nOptions,
this._i18n ? this._i18n.i18next.options : {}
);

if (this._i18nOptions && this._i18nOptions.namespaces) {
const { lng, namespaces } = this._i18nOptions;

const fixedT = this._i18n.i18next.getFixedT(lng, namespaces);
this._getI18nKey = (key, i18nextOptions) =>
fixedT(getKey(key), i18nextOptions, this._i18n.i18nLoadedAt);
fixedT(getKey(key), i18nextOptions, this._i18n.i18nLoadedAt);
} else {
this._getI18nKey = (key, i18nextOptions) =>
this._i18n.t(getKey(key), i18nextOptions, this._i18n.i18nLoadedAt);
}
},
}
});

// extend Vue.js
Object.defineProperty(Vue.prototype, '$i18n', {
get() { return this._i18n; },
get() {
return this._i18n;
}
});

Vue.prototype.$t = function t(key, options) {
Expand Down
1 change: 0 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* eslint-disable import/prefer-default-export */

export function log(message) {
Expand Down
2 changes: 1 addition & 1 deletion src/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export function update(el, binding, vnode, oldVNode) {

export default {
bind,
update,
update
};
Loading

0 comments on commit f454fc2

Please sign in to comment.