Skip to content

Commit a19545f

Browse files
authored
Improve error handling - add more details to errors (#1347)
1 parent b209598 commit a19545f

11 files changed

+40
-18
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ const {
44
getLocalizedFix,
55
addToImports,
66
getComponentLocalName,
7-
getComponentName
7+
getComponentName,
8+
handleError
89
} = require('../utils');
910

11+
const RULE_ID = 'assets-deprecation';
12+
1013
const MAP_SCHEMA = {
1114
type: 'object',
1215
additionalProperties: true
@@ -41,7 +44,7 @@ module.exports = {
4144
}
4245
});
4346
} catch (err) {
44-
console.log('Found error in: ', context.getFilename());
47+
handleError(RULE_ID, err, context.getFilename());
4548
}
4649
}
4750

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('lodash');
2-
const {addToImports, organizeDeprecations, getComponentLocalName, getPossibleDeprecations} = require('../utils');
2+
const {addToImports, organizeDeprecations, getComponentLocalName, getPossibleDeprecations, handleError} = require('../utils');
33

4+
const RULE_ID = 'component-deprecation';
45
const MAP_SCHEMA = {
56
type: 'object',
67
additionalProperties: true
@@ -35,7 +36,7 @@ module.exports = {
3536
}
3637
});
3738
} catch (err) {
38-
console.log('Found error in: ', context.getFilename());
39+
handleError(RULE_ID, err, context.getFilename());
3940
}
4041
}
4142

eslint-rules/lib/rules/component-prop-deprecation.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const {
66
getComponentLocalName,
77
getComponentName,
88
getPossibleDeprecations,
9-
findValueNodeOfIdentifier
9+
findValueNodeOfIdentifier,
10+
handleError
1011
} = require('../utils');
1112

13+
const RULE_ID = 'component-prop-deprecation';
1214
const MAP_SCHEMA = {
1315
type: 'object',
1416
properties: {
@@ -79,7 +81,7 @@ module.exports = {
7981
}
8082
});
8183
} catch (err) {
82-
console.log('Found error in: ', context.getFilename());
84+
handleError(RULE_ID, err, context.getFilename());
8385
}
8486
}
8587

@@ -91,7 +93,7 @@ module.exports = {
9193
message
9294
});
9395
} catch (err) {
94-
console.log('Found error in: ', context.getFilename());
96+
handleError(RULE_ID, err, context.getFilename());
9597
}
9698
}
9799

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const _ = require("lodash");
2+
const {handleError} = require('../utils');
23

4+
const RULE_ID = 'function-deprecation';
35
const MAP_SCHEMA = {
46
type: "object",
57
additionalProperties: true,
@@ -89,7 +91,7 @@ module.exports = {
8991
},
9092
});
9193
} catch (err) {
92-
console.log("Found error in: ", err, context.getFilename());
94+
handleError(RULE_ID, err, context.getFilename());
9395
}
9496
}
9597

eslint-rules/lib/rules/no-direct-import.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const {handleError} = require('../utils');
2+
3+
const RULE_ID = 'no-direct-import';
14
const MAP_SCHEMA = {
25
type: 'object',
36
properties: {
@@ -47,7 +50,7 @@ module.exports = {
4750
},
4851
});
4952
} catch (err) {
50-
console.log('Found error in: ', context.getFilename());
53+
handleError(RULE_ID, err, context.getFilename());
5154
}
5255
}
5356

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('lodash');
2-
const {findAndReportHardCodedValues} = require('../utils');
2+
const {findAndReportHardCodedValues, handleError} = require('../utils');
33

4+
const RULE_ID = 'no-hard-coded-color';
45
const MAP_SCHEMA = {
56
type: 'object',
67
additionalProperties: true
@@ -49,7 +50,7 @@ module.exports = {
4950
});
5051
}
5152
} catch (err) {
52-
console.log('Found error in: ', context.getFilename());
53+
handleError(RULE_ID, err, context.getFilename());
5354
}
5455
}
5556

eslint-rules/lib/rules/prop-value-shape-deprecation.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ const {
55
findValueNodeOfIdentifier,
66
getComponentLocalName,
77
addToImports,
8-
getComponentName
8+
getComponentName,
9+
handleError
910
} = require('../utils');
1011

12+
const RULE_ID = 'prop-value-shape-deprecation';
1113
const MAP_SCHEMA = {
1214
type: 'object',
1315
properties: {
@@ -90,7 +92,7 @@ module.exports = {
9092
}
9193
});
9294
} catch (err) {
93-
console.log('Found error in: ', context.getFilename());
95+
handleError(RULE_ID, err, context.getFilename());
9496
}
9597
}
9698

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ const {
44
getLocalizedFix,
55
addToImports,
66
getComponentLocalName,
7-
getComponentName
7+
getComponentName,
8+
handleError
89
} = require('../utils');
910

11+
const RULE_ID = 'typography-deprecation';
1012
const MAP_SCHEMA = {
1113
type: 'object',
1214
additionalProperties: true
@@ -44,7 +46,7 @@ module.exports = {
4446
}
4547
});
4648
} catch (err) {
47-
console.log('Found error in: ', context.getFilename());
49+
handleError(RULE_ID, err, context.getFilename());
4850
}
4951
}
5052

eslint-rules/lib/utils/generalUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ function findValueNodeOfIdentifier(identifierName, scope) {
3838
return valueNode || findValueNodeOfIdentifier(identifierName, scope.upper);
3939
}
4040

41+
function handleError(ruleId, error, fileName) {
42+
console.log(`Found error in rule: ${ruleId}\n`, `Error: ${error}\n`, `In file: ${fileName}`);
43+
}
44+
4145

4246
module.exports = {
4347
getPrefix,
4448
getSuffix,
45-
findValueNodeOfIdentifier
49+
findValueNodeOfIdentifier,
50+
handleError
4651
};

eslint-rules/lib/utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {getPrefix, getSuffix, findValueNodeOfIdentifier} = require('./generalUtils');
1+
const {getPrefix, getSuffix, findValueNodeOfIdentifier, handleError} = require('./generalUtils');
22
const {organizeDeprecations, getLocalizedFix, getPossibleDeprecations} = require('./deprecationsUtils');
33
const {addToImports} = require('./importUtils');
44
const {getComponentLocalName, getComponentName} = require('./componentUtils');
@@ -10,6 +10,7 @@ module.exports = {
1010
getPrefix,
1111
getSuffix,
1212
findValueNodeOfIdentifier,
13+
handleError,
1314
// Deprecations
1415
organizeDeprecations,
1516
getLocalizedFix,

eslint-rules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-uilib",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"description": "uilib set of eslint rules",
55
"keywords": [
66
"eslint",

0 commit comments

Comments
 (0)