Skip to content

Improve error handling - add more details to errors #1347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions eslint-rules/lib/rules/assets-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const {
getLocalizedFix,
addToImports,
getComponentLocalName,
getComponentName
getComponentName,
handleError
} = require('../utils');

const RULE_ID = 'assets-deprecation';

const MAP_SCHEMA = {
type: 'object',
additionalProperties: true
Expand Down Expand Up @@ -41,7 +44,7 @@ module.exports = {
}
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
5 changes: 3 additions & 2 deletions eslint-rules/lib/rules/component-deprecation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require('lodash');
const {addToImports, organizeDeprecations, getComponentLocalName, getPossibleDeprecations} = require('../utils');
const {addToImports, organizeDeprecations, getComponentLocalName, getPossibleDeprecations, handleError} = require('../utils');

const RULE_ID = 'component-deprecation';
const MAP_SCHEMA = {
type: 'object',
additionalProperties: true
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = {
}
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
8 changes: 5 additions & 3 deletions eslint-rules/lib/rules/component-prop-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const {
getComponentLocalName,
getComponentName,
getPossibleDeprecations,
findValueNodeOfIdentifier
findValueNodeOfIdentifier,
handleError
} = require('../utils');

const RULE_ID = 'component-prop-deprecation';
const MAP_SCHEMA = {
type: 'object',
properties: {
Expand Down Expand Up @@ -79,7 +81,7 @@ module.exports = {
}
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand All @@ -91,7 +93,7 @@ module.exports = {
message
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
4 changes: 3 additions & 1 deletion eslint-rules/lib/rules/function-deprecation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const _ = require("lodash");
const {handleError} = require('../utils');

const RULE_ID = 'function-deprecation';
const MAP_SCHEMA = {
type: "object",
additionalProperties: true,
Expand Down Expand Up @@ -89,7 +91,7 @@ module.exports = {
},
});
} catch (err) {
console.log("Found error in: ", err, context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
5 changes: 4 additions & 1 deletion eslint-rules/lib/rules/no-direct-import.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const {handleError} = require('../utils');

const RULE_ID = 'no-direct-import';
const MAP_SCHEMA = {
type: 'object',
properties: {
Expand Down Expand Up @@ -47,7 +50,7 @@ module.exports = {
},
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
5 changes: 3 additions & 2 deletions eslint-rules/lib/rules/no-hard-coded-color.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require('lodash');
const {findAndReportHardCodedValues} = require('../utils');
const {findAndReportHardCodedValues, handleError} = require('../utils');

const RULE_ID = 'no-hard-coded-color';
const MAP_SCHEMA = {
type: 'object',
additionalProperties: true
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = {
});
}
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
6 changes: 4 additions & 2 deletions eslint-rules/lib/rules/prop-value-shape-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const {
findValueNodeOfIdentifier,
getComponentLocalName,
addToImports,
getComponentName
getComponentName,
handleError
} = require('../utils');

const RULE_ID = 'prop-value-shape-deprecation';
const MAP_SCHEMA = {
type: 'object',
properties: {
Expand Down Expand Up @@ -90,7 +92,7 @@ module.exports = {
}
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
6 changes: 4 additions & 2 deletions eslint-rules/lib/rules/typography-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const {
getLocalizedFix,
addToImports,
getComponentLocalName,
getComponentName
getComponentName,
handleError
} = require('../utils');

const RULE_ID = 'typography-deprecation';
const MAP_SCHEMA = {
type: 'object',
additionalProperties: true
Expand Down Expand Up @@ -44,7 +46,7 @@ module.exports = {
}
});
} catch (err) {
console.log('Found error in: ', context.getFilename());
handleError(RULE_ID, err, context.getFilename());
}
}

Expand Down
7 changes: 6 additions & 1 deletion eslint-rules/lib/utils/generalUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ function findValueNodeOfIdentifier(identifierName, scope) {
return valueNode || findValueNodeOfIdentifier(identifierName, scope.upper);
}

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


module.exports = {
getPrefix,
getSuffix,
findValueNodeOfIdentifier
findValueNodeOfIdentifier,
handleError
};
3 changes: 2 additions & 1 deletion eslint-rules/lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {getPrefix, getSuffix, findValueNodeOfIdentifier} = require('./generalUtils');
const {getPrefix, getSuffix, findValueNodeOfIdentifier, handleError} = require('./generalUtils');
const {organizeDeprecations, getLocalizedFix, getPossibleDeprecations} = require('./deprecationsUtils');
const {addToImports} = require('./importUtils');
const {getComponentLocalName, getComponentName} = require('./componentUtils');
Expand All @@ -10,6 +10,7 @@ module.exports = {
getPrefix,
getSuffix,
findValueNodeOfIdentifier,
handleError,
// Deprecations
organizeDeprecations,
getLocalizedFix,
Expand Down
2 changes: 1 addition & 1 deletion eslint-rules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-uilib",
"version": "2.0.6",
"version": "2.0.7",
"description": "uilib set of eslint rules",
"keywords": [
"eslint",
Expand Down