Skip to content

Commit

Permalink
style: upgrade deps and integrate prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
joshswan committed Sep 22, 2020
1 parent 2fe9dc1 commit 0bf7fdf
Show file tree
Hide file tree
Showing 31 changed files with 3,821 additions and 3,355 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
59 changes: 33 additions & 26 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"useJSXTextNode": true
},
"extends": [
"airbnb",
"airbnb/hooks",
"plugin:@typescript-eslint/recommended",
"airbnb"
"prettier",
"prettier/react",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"plugins": ["prettier", "@typescript-eslint"],
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"ignorePatterns": ["types/"],
"rules": {
"prettier/prettier": ["error"],
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"no-underscore-dangle": ["error", { "allow": ["_raw"] }],
"import/extensions": ["error", "ignorePackages", {
"js": "never",
"mjs": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}],
"no-use-before-define": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"mjs": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
"import/prefer-default-export": "off",
"react/jsx-filename-extension": ["error", { "extensions": [".jsx", ".tsx"] }],
"react/jsx-props-no-spreading": "off",
"react/prop-types": "off",
"react/static-property-placement": ["error", "static public field"],
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "error"
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {
"lines-between-class-members": "off",
"no-dupe-class-members": "off"
}
},
{
"files": ["*.test.*"],
"env": { "jest": true, "node": true },
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.eslintignore
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2
}
5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
*/

module.exports = {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-typescript',
],
presets: ['module:metro-react-native-babel-preset', '@babel/preset-typescript'],
};
75 changes: 45 additions & 30 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
const fs = require('fs');
const path = require('path');
const del = require('del');
const {
dest,
parallel,
series,
src,
} = require('gulp');
const { dest, parallel, series, src } = require('gulp');
const merge = require('gulp-merge-json');
const jsonpack = require('jsonpack/main');
const through = require('through2');
Expand All @@ -23,28 +18,43 @@ const { reduceLocale, reduceSupplemental } = require('./utils/cldr');

const DIR = 'locale-data';

const compress = () => through.obj((file, _, cb) => {
if (file.isBuffer()) {
const content = file.contents.toString('utf8');
// eslint-disable-next-line no-param-reassign
file.contents = Buffer.from(`module.exports=require('jsonpack').unpack('${jsonpack.pack(content).replace(/'/g, "\\'")}')`);
}
const compress = () =>
through.obj((file, _, cb) => {
if (file.isBuffer()) {
const content = file.contents.toString('utf8');
// eslint-disable-next-line no-param-reassign
file.contents = Buffer.from(
`module.exports=require('jsonpack').unpack('${jsonpack
.pack(content)
.replace(/'/g, "\\'")}')`,
);
}

cb(null, file);
});
cb(null, file);
});

function clean() {
return del([`${DIR}/**/*`]);
}

function supplemental() {
const files = ['currencyData', 'likelySubtags', 'numberingSystems', 'ordinals', 'plurals', 'timeData', 'weekData'];
const files = [
'currencyData',
'likelySubtags',
'numberingSystems',
'ordinals',
'plurals',
'timeData',
'weekData',
];

return src(files.map((file) => `node_modules/cldr-data/supplemental/${file}.json`))
.pipe(merge({
fileName: 'core.js',
transform: reduceSupplemental,
}))
.pipe(
merge({
fileName: 'core.js',
transform: reduceSupplemental,
}),
)
.pipe(compress())
.pipe(dest(DIR));
}
Expand All @@ -53,19 +63,24 @@ function locales() {
const files = ['ca-gregorian', 'currencies', 'dateFields', 'numbers', 'timeZoneNames', 'units'];
const dir = 'node_modules/cldr-data/main/';
const ignore = ['en-US-POSIX', 'root'];
const codes = fs.readdirSync(dir)
const codes = fs
.readdirSync(dir)
.filter((file) => fs.statSync(path.join(dir, file)).isDirectory() && !ignore.includes(file));

return stream(codes.map((locale) => src(
files.map((file) => `node_modules/cldr-data/main/${locale}/${file}.json`),
)
.pipe(merge({
fileName: `${locale}.js`,
transform: reduceLocale,
jsonSpace: '',
}))
.pipe(compress())
.pipe(dest(DIR))));
return stream(
codes.map((locale) =>
src(files.map((file) => `node_modules/cldr-data/main/${locale}/${file}.json`))
.pipe(
merge({
fileName: `${locale}.js`,
transform: reduceLocale,
jsonSpace: '',
}),
)
.pipe(compress())
.pipe(dest(DIR)),
),
);
}

exports.default = series(clean, parallel(supplemental, locales));
76 changes: 40 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,62 @@
],
"scripts": {
"build": "tsc",
"cldr": "gulp cldr",
"cldr": "gulp",
"lint": "tsc --noEmit && eslint src test --ext .ts,.tsx",
"release": "release-it",
"test": "jest --coverage"
},
"dependencies": {
"@types/globalize": "^0.0.36",
"@types/react": "^16.9.19",
"@types/react-native": "^0.61.15",
"cldrjs": "^0.5.0",
"dayjs": "^1.8.20",
"globalize": "^1.4.2",
"@types/globalize": "^1.5.0",
"@types/react": "^16.9.49",
"@types/react-native": "^0.63.20",
"cldrjs": "^0.5.4",
"dayjs": "^1.8.36",
"globalize": "^1.6.0",
"hoist-non-react-statics": "^3.3.2",
"jsonpack": "^1.1.5"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/preset-typescript": "^7.8.3",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@release-it/conventional-changelog": "^1.1.0",
"@babel/core": "^7.11.6",
"@babel/preset-typescript": "^7.10.4",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@release-it/conventional-changelog": "^2.0.0",
"@testing-library/react-native": "^7.0.2",
"@types/cldrjs": "^0.4.22",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^25.1.2",
"@types/node": "^13.7.1",
"@typescript-eslint/eslint-plugin": "^2.19.2",
"@typescript-eslint/parser": "^2.19.2",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"cldr-data": "^36.0.0",
"coveralls": "^3.0.9",
"coveralls": "^3.1.0",
"del": "^5.1.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"eslint": "^7.9.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"gulp": "^4.0.2",
"gulp-merge-json": "^2.1.0",
"husky": "^4.2.3",
"jest": "^25.1.0",
"jest-junit": "^10.0.0",
"lodash": "^4.17.15",
"gulp-merge-json": "^2.1.1",
"husky": "^4.3.0",
"jest": "^26.4.2",
"jest-junit": "^11.1.0",
"lodash": "^4.17.20",
"merge-stream": "^2.0.0",
"metro-react-native-babel-preset": "^0.58.0",
"mockdate": "^2.0.5",
"react": "16.9.0",
"react-native": "^0.61.5",
"react-test-renderer": "^16.12.0",
"release-it": "^12.5.0",
"metro-react-native-babel-preset": "^0.63.0",
"mockdate": "^3.0.2",
"prettier": "^2.1.2",
"react": "16.13.1",
"react-native": "^0.63.2",
"react-test-renderer": "^16.13.1",
"release-it": "^14.0.3",
"rimraf": "^3.0.2",
"through2": "^3.0.1",
"typescript": "^3.7.5"
"through2": "^4.0.2",
"typescript": "^4.0.3"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
31 changes: 14 additions & 17 deletions src/components/FormattedPlural.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,22 @@ import { Globalize, PluralGeneratorOptions } from '../globalize';
import { useGlobalize } from '../hooks';
import { createPropFilter, TextProps } from './utils';

type Props = PluralGeneratorOptions & TextProps & {
value: Parameters<Globalize['formatPlural']>[0];
other: React.ReactNode;
zero?: React.ReactNode;
one?: React.ReactNode;
two?: React.ReactNode;
few?: React.ReactNode;
many?: React.ReactNode;
};
type Props = PluralGeneratorOptions &
TextProps & {
value: Parameters<Globalize['formatPlural']>[0];
other: React.ReactNode;
zero?: React.ReactNode;
one?: React.ReactNode;
two?: React.ReactNode;
few?: React.ReactNode;
many?: React.ReactNode;
};

const filterProps = createPropFilter<Props, Parameters<Globalize['formatPlural']>>(({
type,
value,
}) => [value, { type }]);
const filterProps = createPropFilter<Props, Parameters<Globalize['formatPlural']>>(
({ type, value }) => [value, { type }],
);

export const FormattedPlural: React.FC<Props> = ({
children,
...props
}) => {
export const FormattedPlural: React.FC<Props> = ({ children, ...props }) => {
const { formatPlural } = useGlobalize();
const [args, textProps] = filterProps(props);
const plural = formatPlural(...args);
Expand Down
34 changes: 17 additions & 17 deletions src/components/GlobalizeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ export const GlobalizeProvider: React.FC<Props> = ({
localeFallback: fallback = false,
...options
}) => {
const [globalize, setGlobalize] = useState(() => createGlobalize({
...options,
locale,
currencyCode,
defaultLocale,
fallback,
}));

useEffect(() => {
setGlobalize(createGlobalize({
const [globalize, setGlobalize] = useState(() =>
createGlobalize({
...options,
locale,
currencyCode,
defaultLocale,
fallback,
}));
}, [currencyCode, defaultLocale, locale, fallback]);

return (
<GlobalizeContext.Provider value={globalize}>
{children}
</GlobalizeContext.Provider>
}),
);

useEffect(() => {
setGlobalize(
createGlobalize({
...options,
locale,
currencyCode,
defaultLocale,
fallback,
}),
);
}, [currencyCode, defaultLocale, locale, fallback]); // eslint-disable-line react-hooks/exhaustive-deps

return <GlobalizeContext.Provider value={globalize}>{children}</GlobalizeContext.Provider>;
};
Loading

0 comments on commit 0bf7fdf

Please sign in to comment.