Skip to content
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

Make error location clickable in IDE #898

Merged
merged 1 commit into from
Dec 23, 2022
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
8 changes: 8 additions & 0 deletions app/build-config/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { BABEL_INCLUDED_REGEXP, BABEL_EXCLUDED_REGEXP, CSS_URL_ROOT_PATH,
} = require("./constants");
const SVGRLoader = require.resolve("@svgr/webpack");
const FileLoader = require.resolve("file-loader");
const { uuiCustomFormatter } = require("./utils/issueFormatter");

/**
* See https://craco.js.org/
Expand Down Expand Up @@ -89,6 +90,13 @@ function configureWebpack(config, { paths }) {
if (isUseBuildFolderOfDeps()) {
config.resolve.mainFields = ["epam:uui:main", "browser", "module", "main"];
}

config.plugins.forEach(p => {
if (p.constructor.name === 'ForkTsCheckerWebpackPlugin') {
p.options.formatter = uuiCustomFormatter;
}
})

return config;
}

Expand Down
29 changes: 29 additions & 0 deletions app/build-config/utils/issueFormatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { createCodeFrameFormatter } = require('../../../node_modules/fork-ts-checker-webpack-plugin/lib/formatter/CodeFrameFormatter.js')
const path = require('path');
const os = require('os');

module.exports = { uuiCustomFormatter };

const defaultFormatter = createCodeFrameFormatter({});

function uuiCustomFormatter(issue) {
function formatIssueLocation(location) {
return `${location.start.line}:${location.start.column}`;
}
function norm(p) {
return path.normalize(p).replace(/\\+/g, '/')
}
const formattedIssue = defaultFormatter(issue);
if (issue.file) {
// Next line is the main reason why we created custom formatter
// We want error location to be clickable in WebStorm console log.
// In order to make it clickable, the location must be absolute or relative to the root folder, but not relative to "app".
//
let location = norm(issue.file);
if (issue.location) {
location += `:${formatIssueLocation(issue.location)}`;
}
return `${location}${os.EOL}${formattedIssue}`
}
return formattedIssue;
}