Skip to content

Commit 7b4b8a2

Browse files
Inbal-Tishethanshar
authored andcommitted
Eslint rules (#69)
* create initial eslint rule * Adding lint rule no-hard-coded-font (size); fixing lint warnings of hard-coded font size * adding test to no-hard-coded-font rule * adding .eslintignore file; fixing hard-coded colors to use Colors * preparing for npm upload
1 parent f16d577 commit 7b4b8a2

File tree

18 files changed

+226
-18
lines changed

18 files changed

+226
-18
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/src/style/typography.js

.eslintrc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
{
22
"parser": "babel-eslint",
3-
"plugins": ["react-native"],
3+
"plugins": ["react-native", "uilib"],
44
"extends": ["airbnb"],
55
"rules": {
6-
"object-curly-spacing": "off",
7-
"react/prefer-stateless-function": "off",
8-
"react/jsx-filename-extension": "off",
9-
"react/require-default-props": "off",
6+
"arrow-body-style": "off",
7+
"class-methods-use-this": "off",
8+
"consistent-return": "off",
9+
"global-require": "off",
10+
"import/prefer-default-export": "off",
11+
"no-plusplus": "off",
12+
"no-return-assign": "off",
1013
"no-use-before-define": "off",
14+
"max-len": [2, 120, 4, {"ignoreUrls": true}],
15+
"object-curly-spacing": "off",
1116
"react/forbid-prop-types": "off",
17+
"react/jsx-filename-extension": "off",
1218
"react/jsx-space-before-closing": "off",
1319
"react/jsx-tag-spacing": "off",
14-
"max-len": [2, 120, 4, {"ignoreUrls": true}],
15-
"class-methods-use-this": "off",
16-
"arrow-body-style": "off",
17-
"no-plusplus": "off",
18-
"import/prefer-default-export": "off",
19-
"global-require": "off",
20-
"consistent-return": "off",
21-
"no-return-assign": "off"
20+
"react/prefer-stateless-function": "off",
21+
"react/require-default-props": "off",
22+
"uilib/no-hard-coded-font": "warn"
2223
},
2324
"env": {
2425
"browser": true,

.npmignore

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

eslint-rules/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# eslint-plugin-uilib
2+
3+
uilib set of eslint rules
4+
5+
## Installation
6+
7+
You'll first need to install [ESLint](http://eslint.org):
8+
9+
```
10+
$ npm i eslint --save-dev
11+
```
12+
13+
Next, install `eslint-plugin-uilib`:
14+
15+
```
16+
$ npm install eslint-plugin-uilib --save-dev
17+
```
18+
19+
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-uilib` globally.
20+
21+
## Usage
22+
23+
Add `uilib` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
24+
25+
```json
26+
{
27+
"plugins": [
28+
"uilib"
29+
]
30+
}
31+
```
32+
33+
34+
Then configure the rules you want to use under the rules section.
35+
36+
```json
37+
{
38+
"rules": {
39+
"uilib/rule-name": 2
40+
}
41+
}
42+
```
43+
44+
## Supported Rules
45+
46+
* Fill in provided rules here
47+
48+
49+
50+
51+

eslint-rules/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'no-hard-coded-font': require('./lib/rules/no-hard-coded-font'),
4+
},
5+
};

eslint-rules/lib/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @fileoverview uilib set of eslint rules
3+
* @author Ethan Sharabi
4+
*/
5+
6+
'use strict';
7+
8+
//------------------------------------------------------------------------------
9+
// Requirements
10+
//------------------------------------------------------------------------------
11+
12+
const requireIndex = require('requireindex');
13+
14+
//------------------------------------------------------------------------------
15+
// Plugin Definition
16+
//------------------------------------------------------------------------------
17+
18+
// import all rules in lib/rules
19+
module.exports.rules = requireIndex(__dirname + "/rules");

eslint-rules/lib/rules/no-hard-coded-color.js

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @fileoverview Rule to disallow hard coded font style
3+
* @author Inbal Tish
4+
*/
5+
6+
'use strict';
7+
8+
//------------------------------------------------------------------------------
9+
// Rule Definition
10+
//------------------------------------------------------------------------------
11+
12+
module.exports = {
13+
meta: {
14+
docs: {
15+
description: 'disallow hard coded font style',
16+
category: 'Possible Errors',
17+
recommended: true,
18+
},
19+
messages: {
20+
reportMessage: 'Please do not use hard coded fontSize prop in style objects, instead use Typography presets',
21+
},
22+
fixable: 'code',
23+
schema: [], // no options
24+
},
25+
create(context) {
26+
return {
27+
ObjectExpression: function (node) {
28+
node.properties.forEach((property) => {
29+
if (property.key) {
30+
const propName = property.key.name;
31+
if (propName === 'fontSize') {
32+
if (property.value.type === 'CallExpression') {
33+
return;
34+
}
35+
if (property.value.type === 'MemberExpression') {
36+
const objectName = property.value.object.object.name;
37+
if (objectName.toLowerCase() === 'typography') {
38+
return;
39+
}
40+
}
41+
// console.log(`${property.value.value} should be fixed!`);
42+
context.report({
43+
node,
44+
messageId: 'reportMessage',
45+
});
46+
}
47+
}
48+
});
49+
},
50+
};
51+
},
52+
};

eslint-rules/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "eslint-plugin-uilib",
3+
"version": "1.0.0",
4+
"description": "uilib set of eslint rules",
5+
"keywords": [
6+
"eslint",
7+
"eslintplugin",
8+
"eslint-plugin"
9+
],
10+
"author": "Tnbal Tish <[email protected]>",
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "mocha tests --recursive"
14+
},
15+
"dependencies": {
16+
"requireindex": "~1.1.0"
17+
},
18+
"devDependencies": {
19+
"eslint": "~3.9.1",
20+
"mocha": "^3.1.2"
21+
},
22+
"engines": {
23+
"node": ">=0.10.0"
24+
},
25+
"license": "ISC"
26+
}

eslint-rules/tests/lib/rules/no-hard-coded-color.js

Whitespace-only changes.

0 commit comments

Comments
 (0)