Skip to content

Commit b04095a

Browse files
committed
Use eslint-config-i-am-meticulous instead of custom.
1 parent a17b74e commit b04095a

File tree

6 files changed

+16
-98
lines changed

6 files changed

+16
-98
lines changed

.eslintrc

-86
This file was deleted.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@
3131
"cross-env": "^3.1.4",
3232
"del-cli": "^0.2.1",
3333
"eslint": "^3.12.2",
34+
"eslint-config-i-am-meticulous": "^6.0.1",
3435
"eslint-plugin-babel": "^4.0.0",
3536
"eslint-plugin-import": "^2.2.0",
3637
"jison": "^0.4.17"
3738
},
3839
"dependencies": {
3940
"css-unit-converter": "^1.1.1",
4041
"postcss-value-parser": "^3.3.0"
42+
},
43+
"eslintConfig": {
44+
"parser": "babel-eslint",
45+
"extends": "eslint-config-i-am-meticulous"
4146
}
4247
}

src/__tests__/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import test from 'ava';
2+
23
import reduceCalc from '..';
34

45
function testFixture(t, fixture, expected = null, precision = 5) {

src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import valueParser from 'postcss-value-parser';
2-
import { parser } from './parser';
2+
3+
import { parser } from './parser'; // eslint-disable-line
34
import reducer from './lib/reducer';
45
import stringifier from './lib/stringifier';
56

@@ -12,12 +13,12 @@ export default (value, precision = 5) => {
1213
return;
1314

1415
// stringify calc expression and produce an AST
15-
let contents = valueParser.stringify(node.nodes);
16-
let ast = parser.parse(contents);
16+
const contents = valueParser.stringify(node.nodes);
17+
const ast = parser.parse(contents);
1718

1819
// reduce AST to its simplest form, that is, either to a single value
1920
// or a simplified calc expression
20-
let reducedAst = reducer(ast, precision);
21+
const reducedAst = reducer(ast, precision);
2122

2223
// stringify AST and write it back
2324
node.type = 'word';

src/lib/reducer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ function convertMathExpression(node, precision) {
4141
}
4242

4343
function reduceAddSubExpression(node, precision) {
44-
let op = node.operator;
45-
let left = node.left;
46-
let right = node.right;
44+
const {left, right, operator: op} = node;
4745

4846
// something + 0 => something
4947
// something - 0 => something

src/lib/stringifier.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ const order = {
77

88
function round(value, prec) {
99
if (prec !== false) {
10-
let precision = Math.pow(10, prec);
10+
const precision = Math.pow(10, prec);
1111
return Math.round(value * precision) / precision;
1212
}
1313
return value;
1414
}
1515

1616
function stringify(node, prec) {
1717
switch (node.type) {
18-
case "MathExpression":
19-
let op = node.operator;
20-
let left = node.left;
21-
let right = node.right;
18+
case "MathExpression": {
19+
const {left, right, operator: op} = node;
2220
let str = "";
2321

2422
if (left.type === 'MathExpression' && order[op] < order[left.operator])
@@ -34,6 +32,7 @@ function stringify(node, prec) {
3432
str += stringify(right, prec);
3533

3634
return str;
35+
}
3736
case "Value":
3837
return round(node.value, prec);
3938
default:

0 commit comments

Comments
 (0)