Skip to content

Commit 7a49059

Browse files
committed
Merge branch 'master' into release
2 parents 83d93ac + effea44 commit 7a49059

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2125
-479
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ android/
232232
demo/
233233
expoDemo/
234234
uilib-docs/
235+
markdowns/
235236
.babelrc
236237
# typings/
237238
# eslint-rules/

demo/src/screens/componentScreens/TagsInputScreen.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class TagsInputScreen extends Component {
88
super(props);
99

1010
this.state = {
11-
tags: [{label: 'Amit'}, {label: 'Ethan'}],
11+
tags: [{label: 'Amit'}, {label: 'Ethan', invalid: true}],
1212
tags2: ['Tags', 'Input'],
1313
tags3: ['Non', 'Removable', 'Tags']
1414
};
@@ -36,6 +36,9 @@ export default class TagsInputScreen extends Component {
3636

3737
<TagsInput containerStyle={{marginBottom: 25}} placeholder="Enter Tags" tags={this.state.tags2}/>
3838

39+
<TagsInput containerStyle={{marginBottom: 25}} placeholder="Enter Tags" tags={this.state.tags}
40+
validationErrorMessage="error validation message" />
41+
3942
<TagsInput
4043
containerStyle={{marginBottom: 25}}
4144
placeholder="Editing disabled"

demo/src/screens/componentScreens/TextFieldScreen/BasicTextFieldScreen.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class BasicTextFieldScreen extends Component {
2727

2828
this.state = {
2929
hideUnderline: false,
30+
withPrefix: false,
3031
underlineColor: undefined,
3132
guidingText: GUIDING_TEXTS.none,
3233
disabled: false,
@@ -43,6 +44,7 @@ export default class BasicTextFieldScreen extends Component {
4344
render() {
4445
const {
4546
hideUnderline,
47+
withPrefix,
4648
underlineColor,
4749
guidingText,
4850
titleColor,
@@ -64,6 +66,7 @@ export default class BasicTextFieldScreen extends Component {
6466
placeholder={disabled ? 'Disabled' : 'Placeholder'}
6567
hideUnderline={hideUnderline}
6668
underlineColor={underlineColor}
69+
prefix={withPrefix ? 'prefix://' : undefined}
6770
title={guidingText === GUIDING_TEXTS.useTitle ? 'Title' : undefined}
6871
titleColor={titleColor}
6972
floatingPlaceholder={guidingText === GUIDING_TEXTS.floatingPlaceholder}
@@ -94,6 +97,7 @@ export default class BasicTextFieldScreen extends Component {
9497
{renderBooleanOption.call(this, 'Disabled', 'disabled')}
9598
{renderBooleanOption.call(this, 'Centered', 'centered')}
9699
{renderBooleanOption.call(this, 'Hide Underline', 'hideUnderline')}
100+
{renderBooleanOption.call(this, 'With Prefix', 'withPrefix')}
97101
{renderColorOption.call(this, 'Underline Color', 'underlineColor')}
98102
{renderRadioGroup.call(this, 'Guiding Text', 'guidingText', GUIDING_TEXTS)}
99103
{renderColorOption.call(this, 'Title Color', 'titleColor')}

demo/src/screens/componentScreens/TextFieldScreen/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TextFieldScreen extends Component {
2020

2121
renderPages() {
2222
return (
23-
<TabController.PageCarousel>
23+
<View flex>
2424
{_.map(SCREENS, (item, index) => {
2525
const Screen = item.screen;
2626
return (
@@ -29,13 +29,13 @@ class TextFieldScreen extends Component {
2929
</TabController.TabPage>
3030
);
3131
})}
32-
</TabController.PageCarousel>
32+
</View>
3333
);
3434
}
3535

3636
render() {
3737
return (
38-
<TabController asCarousel>
38+
<TabController>
3939
<TabController.TabBar
4040
items={SCREENS.map(item => ({label: item.title}))}
4141
activeBackgroundColor={Colors.blue70}

eslint-rules/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ module.exports = {
44
'no-direct-import': require('./lib/rules/no-direct-import'),
55
'component-deprecation': require('./lib/rules/component-deprecation'),
66
'assets-deprecation': require('./lib/rules/assets-deprecation'),
7+
'typography-deprecation': require('./lib/rules/typography-deprecation'),
78
// for duplicate rules usage
89
'component-deprecation_warn': require('./lib/rules/component-deprecation'),
910
'assets-deprecation_warn': require('./lib/rules/assets-deprecation'),
11+
'typography-deprecation_warn': require('./lib/rules/typography-deprecation'),
1012
'component-deprecation_error': require('./lib/rules/component-deprecation'),
1113
'assets-deprecation_error': require('./lib/rules/assets-deprecation'),
14+
'typography-deprecation_error': require('./lib/rules/typography-deprecation'),
1215
},
1316
};

eslint-rules/lib/rules/assets-deprecation.js

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,76 +39,56 @@ module.exports = {
3939
}
4040
}
4141

42-
// Path
43-
let pathString = '';
42+
const defaultImportName = 'Assets';
43+
const {deprecations, source} = context.options[0];
44+
let localImportSpecifier;
4445

45-
function deprecationCheck(node) {
46-
if (node) {
47-
const check = isAssetsObject(node);
48-
if (check && pathString !== '') {
49-
const deprecatedObject = getDeprecatedObject(pathString);
50-
if (deprecatedObject) {
51-
const {path, message, fix} = deprecatedObject;
52-
reportDeprecatedAssets(node, {path, message, fix});
53-
}
54-
}
55-
}
46+
function setLocalImportSpecifier(node) {
47+
localImportSpecifier = utils.getLocalImportSpecifier(node, source, defaultImportName);
5648
}
5749

58-
function isAssetsObject(node) {
50+
function getAssetString(node, pathString = '') {
5951
if (node) {
6052
if (node.object) {
6153
if (node.property && node.property.name) {
6254
pathString = (pathString === '') ? `${node.property.name}` : `${node.property.name}.${pathString}`;
63-
return isAssetsObject(node.object);
55+
return getAssetString(node.object, pathString);
6456
}
65-
} else if (node.name === assetsName) {
57+
} else if (node.name === localImportSpecifier) {
6658
pathString = `${node.name}.${pathString}`;
67-
return true;
59+
return pathString;
6860
}
6961
}
70-
pathString = '';
71-
return false;
72-
}
73-
74-
const {deprecations} = context.options[0];
7562

76-
function getDeprecatedObject(path) {
77-
return _.find(deprecations, {path});
63+
return undefined;
7864
}
7965

80-
function checkSpreadAttribute(node) {
81-
const spreadSource = utils.findValueNodeOfIdentifier(node.argument.name, context.getScope());
82-
if (spreadSource && spreadSource.properties) {
83-
_.forEach(spreadSource.properties, (property) => {
84-
deprecationCheck(property);
85-
});
66+
function findAndReportDeprecation(node, possibleDeprecation) {
67+
possibleDeprecation = possibleDeprecation.replace(localImportSpecifier, defaultImportName);
68+
const deprecatedObject = _.find(deprecations, {path: possibleDeprecation});
69+
if (deprecatedObject) {
70+
reportDeprecatedAssets(node, deprecatedObject);
8671
}
8772
}
8873

89-
// Import
90-
const {source} = context.options[0];
91-
const assetsName = 'Assets';
92-
let shouldCheckDeprecation = false;
93-
94-
function checkAssetsImport(node) {
95-
const importSource = node.source.value;
96-
97-
if (source === importSource) {
98-
const specifiers = node.specifiers;
99-
if (specifiers) {
100-
shouldCheckDeprecation = _.find(specifiers, e => e.local.name === assetsName);
101-
}
74+
function testMemberDeprecation(node) {
75+
const assetString = getAssetString(node);
76+
if (assetString) {
77+
findAndReportDeprecation(node, assetString);
10278
}
10379
}
10480

10581
return {
106-
ImportDeclaration: node => checkAssetsImport(node),
107-
// MemberExpression: node => shouldCheckDeprecation && deprecationCheck(node),
108-
VariableDeclarator: node => shouldCheckDeprecation && deprecationCheck(node.init),
109-
Property: node => shouldCheckDeprecation && deprecationCheck(node.value),
110-
JSXAttribute: node => shouldCheckDeprecation && node.value && deprecationCheck(node.value.expression),
111-
JSXSpreadAttribute: node => shouldCheckDeprecation && checkSpreadAttribute(node),
82+
ImportDeclaration: node => !localImportSpecifier && setLocalImportSpecifier(node),
83+
MemberExpression: node => localImportSpecifier && testMemberDeprecation(node),
84+
85+
86+
// VariableDeclarator: node => testVariableDeclarator(node),
87+
// JSXAttribute: node => testJSXAttribute(node),
88+
// JSXOpeningElement: node => testJSXOpeningElement(node),
89+
// JSXSpreadAttribute: node => testJSXSpreadAttribute(node),
90+
// ObjectExpression: node => testObjectExpression(node),
91+
// Property: node => testProperty(node),
11292
};
11393
},
11494
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const _ = require('lodash');
2+
const utils = require('../utils');
3+
4+
const MAP_SCHEMA = {
5+
type: 'object',
6+
additionalProperties: true,
7+
};
8+
9+
module.exports = {
10+
meta: {
11+
docs: {
12+
description: 'typography is deprecated',
13+
category: 'Best Practices',
14+
recommended: true,
15+
},
16+
messages: {
17+
uiLib: 'This typography is deprecated.',
18+
},
19+
fixable: 'code',
20+
schema: [MAP_SCHEMA],
21+
},
22+
create(context) {
23+
function reportDeprecatedTypography(node, options) {
24+
try {
25+
const {dueDate} = context.options[0];
26+
const dueDateNotice = dueDate ? ` Please fix this issue by ${dueDate}!` : '';
27+
const msg = `'${options.path}' is deprecated. ${options.message}${dueDateNotice}`;
28+
context.report({
29+
node,
30+
message: `${msg}`,
31+
fix(fixer) {
32+
if (options.fix) {
33+
return fixer.replaceText(node, options.fix);
34+
}
35+
},
36+
});
37+
} catch (err) {
38+
console.log('Found error in: ', context.getFilename());
39+
}
40+
}
41+
42+
const defaultImportName = 'Typography';
43+
const {deprecations, source} = context.options[0];
44+
let localImportSpecifier;
45+
46+
function setLocalImportSpecifier(node) {
47+
localImportSpecifier = utils.getLocalImportSpecifier(node, source, defaultImportName);
48+
}
49+
50+
function findAndReportDeprecation(node, possibleDeprecation) {
51+
const path = `${defaultImportName}.${possibleDeprecation}`;
52+
const foundDeprecation = _.find(deprecations, {path});
53+
if (foundDeprecation) {
54+
reportDeprecatedTypography(node, foundDeprecation);
55+
}
56+
}
57+
58+
function testMemberDeprecation(node) {
59+
if (node && node.object && node.property && node.object.name === localImportSpecifier) {
60+
findAndReportDeprecation(node, node.property.name);
61+
}
62+
}
63+
64+
function testJSXAttribute(node) {
65+
if (node && node.name) {
66+
findAndReportDeprecation(node, node.name.name);
67+
}
68+
}
69+
70+
return {
71+
ImportDeclaration: node => !localImportSpecifier && setLocalImportSpecifier(node),
72+
MemberExpression: node => localImportSpecifier && testMemberDeprecation(node),
73+
JSXAttribute: node => testJSXAttribute(node),
74+
75+
76+
// JSXOpeningElement: node => testJSXOpeningElement(node),
77+
// ObjectExpression: node => testObjectExpression(node),
78+
// VariableDeclarator: node => testVariableDeclarator(node),
79+
// Property: node => testProperty(node),
80+
// JSXSpreadAttribute: node => testJSXSpreadAttribute(node)
81+
};
82+
},
83+
};

eslint-rules/lib/utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const _ = require('lodash');
2+
13
// no-hard-coded-color
24
const colorProps = [
35
'color', 'backgroundColor', 'borderColor', 'borderRightColor',
@@ -57,11 +59,32 @@ function findValueNodeOfIdentifier(identifierName, scope) {
5759
return valueNode;
5860
}
5961

62+
function getLocalImportSpecifier(node, source, defaultImportName) {
63+
let localImportSpecifier;
64+
const importSource = node.source.value;
65+
if (source === importSource) {
66+
const specifiers = node.specifiers;
67+
if (specifiers) {
68+
localImportSpecifier = _.find(specifiers, specifier => specifier.imported && specifier.imported.name === defaultImportName);
69+
if (localImportSpecifier) {
70+
localImportSpecifier = localImportSpecifier.local.name;
71+
}
72+
}
73+
74+
if (!localImportSpecifier) { // someone is importing everything (*)
75+
localImportSpecifier = defaultImportName;
76+
}
77+
}
78+
79+
return localImportSpecifier;
80+
}
81+
6082
module.exports = {
6183
isPropFont,
6284
findAndReportHardCodedValues,
6385
propIsColor,
6486
isColorException,
6587
isLiteral,
6688
findValueNodeOfIdentifier,
89+
getLocalImportSpecifier,
6790
};

eslint-rules/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-uilib",
3-
"version": "1.0.19",
3+
"version": "1.0.23",
44
"description": "uilib set of eslint rules",
55
"keywords": [
66
"eslint",
@@ -28,7 +28,7 @@
2828
"devDependencies": {
2929
"babel-cli": "^6.23.0",
3030
"babel-eslint": "^7.0.0",
31-
"babel-jest": "^20.0.3",
31+
"babel-jest": "^25.5.1",
3232
"babel-preset-es2015": "^6.22.0",
3333
"babel-preset-react": "^6.22.0",
3434
"babel-preset-react-native": "1.9.1",
@@ -38,7 +38,7 @@
3838
"eslint-plugin-node": "^6.0.1",
3939
"eslint-plugin-promise": "^3.7.0",
4040
"eslint-plugin-standard": "^3.0.1",
41-
"mocha": "^3.1.2"
41+
"mocha": "7.1.2"
4242
},
4343
"engines": {
4444
"node": ">=0.10.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"path": "Assets.icons.deprecated",
4-
"message": "Use 'Assets.icons.general.valid' instead.",
4+
"message": "Please use 'Assets.icons.general.valid' instead (fix is available).",
55
"fix": "Assets.icons.general.valid"
66
}
77
]

0 commit comments

Comments
 (0)