Skip to content

Commit

Permalink
chore: set up linting for typescript definitions (#890)
Browse files Browse the repository at this point in the history
* chore: set up linting for typescript definitions

* chore(deps): upgrade typescript to latest version
  • Loading branch information
rchl committed May 25, 2020
1 parent 2888bbd commit aef0bfa
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 94 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.*/node_modules/.*
.*/docs/.*
.*/test/.*
.*/types/.*
.*/config/.*
.*/examples/.*

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-syntax-flow": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"@vue/babel-preset-app": "^3.0.1",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.0.2",
Expand Down Expand Up @@ -75,7 +77,7 @@
"shipjs": "^0.17.0",
"sinon": "^2.1.0",
"terser": "^3.17.0",
"typescript": "^2.4.1",
"typescript": "^3.9.3",
"vue": "^2.5.17",
"vue-github-button": "^1.1.2",
"vue-template-compiler": "^2.5.17",
Expand Down Expand Up @@ -122,7 +124,7 @@
"docs:clean": "rm -rf docs/**",
"docs:dev": "vuepress dev vuepress",
"flow": "flow check",
"lint": "eslint --fix src test",
"lint": "eslint --fix src test types/**/*.ts",
"release:prepare": "shipjs prepare",
"release:trigger": "shipjs trigger",
"sauce": "npm run sauce:coolkids && npm run sauce:ie && npm run sauce:mobile",
Expand Down
20 changes: 20 additions & 0 deletions types/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2018,
},
extends: [
'plugin:@typescript-eslint/eslint-recommended',
],
plugins: [
'@typescript-eslint',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
},
rules: {
'object-curly-spacing': ['error', 'always'],
'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 1 }]
}
}
8 changes: 4 additions & 4 deletions types/test/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue, { ComponentOptions } from 'vue';
import VueI18n from "../index";
import Vue from 'vue'
import VueI18n from '../index'

// setup locale info for root Vue instance
const i18n = new VueI18n({
Expand Down Expand Up @@ -33,8 +33,8 @@ const Component1 = {
ja: { message: { hello: 'こんにちは、component1' } }
},
sharedMessages: {
en: { buttons: { save: 'Save'} },
ja: { buttons: { save: 'Save'} }
en: { buttons: { save: 'Save' } },
ja: { buttons: { save: 'Save' } }
}
}
}
Expand Down
166 changes: 83 additions & 83 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue, { ComponentOptions } from 'vue';
import VueI18n, { DateTimeFormatOptions, NumberFormatOptions } from "../index";
import Vue from 'vue'
import VueI18n, { DateTimeFormatOptions, NumberFormatOptions } from '../index'

/*
import * as VueI18n from 'vue-i18n';
Expand All @@ -8,33 +8,33 @@ import * as Vue from 'vue';
/**
* VueI18n.install
*/
Vue.use(VueI18n);
VueI18n.install(Vue);
Vue.use(VueI18n)
VueI18n.install(Vue)

/**
* VueI18n.version
*/
VueI18n.version; // $ExpectType string
VueI18n.version // $ExpectType string

/**
* VueI18n.availabilities
*/
VueI18n.availabilities; // $ExpectType IntlAvailability
VueI18n.availabilities // $ExpectType IntlAvailability

/**
* VueI18n Instance
*/
const locale = 'locale';
const key = 'key';
const value = 'value';
const locale = 'locale'
const key = 'key'
const value = 'value'
const dateTimeFormatOptions: DateTimeFormatOptions = {
year: '2-digit',
timeZone: 'Asia/Tokyo'
};
}
const numberFormatOptions: NumberFormatOptions = {
style: 'currency',
currency: 'JPY'
};
}
const i18n = new VueI18n({
locale,
fallbackLocale: locale,
Expand All @@ -54,103 +54,103 @@ const i18n = new VueI18n({
}
},
formatter: {
interpolate(message, values) {
return [message];
},
interpolate (message, values) {
return [message]
}
},
modifiers: {
foo: (str) => 'bar'
},
missing(locale, key, vm) {
missing (locale, key, vm) {
},
fallbackRoot: false,
sync: true,
silentTranslationWarn: true,
silentFallbackWarn: true,
preserveDirectiveContent: true,
});
i18n.messages[locale][key]; // $ExpectType LocaleMessage
i18n.dateTimeFormats[locale][key]; // $ExpectType DateTimeFormatOptions
i18n.numberFormats[locale][key]; // $ExpectType NumberFormatOptions
i18n.locale; // $ExpectType string
i18n.fallbackLocale; // $ExpectType string
i18n.missing; // $ExpectType MissingHandler
i18n.formatter; // $ExpectType Formatter
i18n.silentTranslationWarn; // $ExpectType boolean
i18n.silentFallbackWarn; // $ExpectType boolean
i18n.preserveDirectiveContent; // $ExpectType boolean
i18n.setLocaleMessage; // $ExpectType (locale: string, message: LocaleMessageObject) => void
i18n.getLocaleMessage; // $ExpectType (locale: string) => LocaleMessageObject
i18n.mergeLocaleMessage; // $ExpectType (locale: string, message: LocaleMessageObject) => void
i18n.setDateTimeFormat; // $ExpectType (locale: string, format: DateTimeFormat) => void
i18n.getDateTimeFormat; // $ExpectType (locale: string) => DateTimeFormat
i18n.mergeDateTimeFormat; // $ExpectType (locale: string, format: DateTimeFormat) => void
i18n.setNumberFormat; // $ExpectType (locale: string, format: NumberFormat) => void
i18n.getNumberFormat; // $ExpectType (locale: string) => NumberFormat
i18n.mergeNumberFormat; // $ExpectType (locale: string, format: NumberFormat) => void
preserveDirectiveContent: true
})
i18n.messages[locale][key] // $ExpectType LocaleMessage
i18n.dateTimeFormats[locale][key] // $ExpectType DateTimeFormatOptions
i18n.numberFormats[locale][key] // $ExpectType NumberFormatOptions
i18n.locale // $ExpectType string
i18n.fallbackLocale // $ExpectType string
i18n.missing // $ExpectType MissingHandler
i18n.formatter // $ExpectType Formatter
i18n.silentTranslationWarn // $ExpectType boolean
i18n.silentFallbackWarn // $ExpectType boolean
i18n.preserveDirectiveContent // $ExpectType boolean
i18n.setLocaleMessage // $ExpectType (locale: string, message: LocaleMessageObject) => void
i18n.getLocaleMessage // $ExpectType (locale: string) => LocaleMessageObject
i18n.mergeLocaleMessage // $ExpectType (locale: string, message: LocaleMessageObject) => void
i18n.setDateTimeFormat // $ExpectType (locale: string, format: DateTimeFormat) => void
i18n.getDateTimeFormat // $ExpectType (locale: string) => DateTimeFormat
i18n.mergeDateTimeFormat // $ExpectType (locale: string, format: DateTimeFormat) => void
i18n.setNumberFormat // $ExpectType (locale: string, format: NumberFormat) => void
i18n.getNumberFormat // $ExpectType (locale: string) => NumberFormat
i18n.mergeNumberFormat // $ExpectType (locale: string, format: NumberFormat) => void
// $ExpectType { (key: string, values?: { [key: string]: any; } | undefined): TranslateResult; (key: string, locale: string, values?: { [key: string]: any; } | undefined): TranslateResult; }
i18n.t;
i18n.t
// tslint:disable-next-line:max-line-length
// $ExpectType { (key: string, choice?: number | undefined, values?: { [key: string]: any; } | undefined): string; (key: string, choice: number, locale: string, values?: { [key: string]: any; } | undefined): string; }
i18n.tc;
i18n.tc
// $ExpectType (key: string, locale?: string | undefined) => boolean
i18n.te;
i18n.te
// tslint:disable-next-line:max-line-length
// $ExpectType { (value: number | Date, key?: string | undefined, locale?: string | undefined): string; (value: number | Date, args?: { [key: string]: string; } | undefined): string; }
i18n.d;
i18n.d
// tslint:disable-next-line:max-line-length
// $ExpectType { (value: number, key?: string | undefined, locale?: string | undefined): string; (value: number, args?: { [key: string]: string; } | undefined): string; }
i18n.n;
i18n.n

/**
* Vue
*/
const vm = new Vue({
i18n,
});
vm.$i18n; // $ExpectType VueI18n
vm.$t(key); // $ExpectType TranslateResult
vm.$t(key, ['', 0, false, null, undefined]); // $ExpectType TranslateResult
vm.$t(key, { x: 'x' }); // $ExpectType TranslateResult
vm.$t(key, locale);
vm.$t(key, locale, ['', 0, false, null, undefined]); // $ExpectType TranslateResult
vm.$t(key, locale, { x: 'x' }); // $ExpectType TranslateResult
vm.$tc(key); // $ExpectType string
vm.$tc(key, 1); // $ExpectType string
vm.$tc(key, 1, []); // $ExpectType string
vm.$tc(key, 1, {}); // $ExpectType string
vm.$tc(key, 1, locale); // $ExpectType string
vm.$tc(key, 1, locale, []); // $ExpectType string
vm.$tc(key, 1, locale, {}); // $ExpectType string
vm.$te(key); // $ExpectType boolean
vm.$te(key, locale); // $ExpectType boolean
vm.$d(1, key); // $ExpectType string
vm.$d(1, key, locale); // $ExpectType string
vm.$d(new Date(), { key, locale }); // $ExpectType string
vm.$n(1, key); // $ExpectType string
vm.$n(1, key, locale); // $ExpectType string
vm.$n(100, { key, locale }); // $ExpectType string
i18n
})
vm.$i18n // $ExpectType VueI18n
vm.$t(key) // $ExpectType TranslateResult
vm.$t(key, ['', 0, false, null, undefined]) // $ExpectType TranslateResult
vm.$t(key, { x: 'x' }) // $ExpectType TranslateResult
vm.$t(key, locale)
vm.$t(key, locale, ['', 0, false, null, undefined]) // $ExpectType TranslateResult
vm.$t(key, locale, { x: 'x' }) // $ExpectType TranslateResult
vm.$tc(key) // $ExpectType string
vm.$tc(key, 1) // $ExpectType string
vm.$tc(key, 1, []) // $ExpectType string
vm.$tc(key, 1, {}) // $ExpectType string
vm.$tc(key, 1, locale) // $ExpectType string
vm.$tc(key, 1, locale, []) // $ExpectType string
vm.$tc(key, 1, locale, {}) // $ExpectType string
vm.$te(key) // $ExpectType boolean
vm.$te(key, locale) // $ExpectType boolean
vm.$d(1, key) // $ExpectType string
vm.$d(1, key, locale) // $ExpectType string
vm.$d(new Date(), { key, locale }) // $ExpectType string
vm.$n(1, key) // $ExpectType string
vm.$n(1, key, locale) // $ExpectType string
vm.$n(100, { key, locale }) // $ExpectType string

/**
* VueI18n
*/
{
let path: VueI18n.Path;
let locale: VueI18n.Locale;
let values: VueI18n.Values;
let choice: VueI18n.Choice;
let localeMessage: VueI18n.LocaleMessage;
let localeMessageObject: VueI18n.LocaleMessageObject;
let localeMessageArray: VueI18n.LocaleMessageArray;
let localeMessages: VueI18n.LocaleMessages;
let translateResult: VueI18n.TranslateResult;
let dateTimeFormatOptions: VueI18n.DateTimeFormatOptions;
let dateTimeFormat: VueI18n.DateTimeFormat;
let dateTimeFormats: VueI18n.DateTimeFormats;
let numberFormatOptions: VueI18n.NumberFormatOptions;
let NumberFormat: VueI18n.NumberFormat;
let numberFormats: VueI18n.NumberFormats;
let formatter: VueI18n.Formatter;
let missingHandler: VueI18n.MissingHandler;
let i18nOptions: VueI18n.I18nOptions;
let path: VueI18n.Path
let locale: VueI18n.Locale
let values: VueI18n.Values
let choice: VueI18n.Choice
let localeMessage: VueI18n.LocaleMessage
let localeMessageObject: VueI18n.LocaleMessageObject
let localeMessageArray: VueI18n.LocaleMessageArray
let localeMessages: VueI18n.LocaleMessages
let translateResult: VueI18n.TranslateResult
let dateTimeFormatOptions: VueI18n.DateTimeFormatOptions
let dateTimeFormat: VueI18n.DateTimeFormat
let dateTimeFormats: VueI18n.DateTimeFormats
let numberFormatOptions: VueI18n.NumberFormatOptions
let NumberFormat: VueI18n.NumberFormat
let numberFormats: VueI18n.NumberFormats
let formatter: VueI18n.Formatter
let missingHandler: VueI18n.MissingHandler
let i18nOptions: VueI18n.I18nOptions
}

0 comments on commit aef0bfa

Please sign in to comment.