2020-06-30 09:22:25 +02:00
|
|
|
import React from 'react';
|
2020-07-09 18:53:51 +02:00
|
|
|
|
|
|
|
import { makeStyles } from '@material-ui/core/styles';
|
2020-06-29 23:43:49 +02:00
|
|
|
import Container from '@material-ui/core/Container';
|
|
|
|
import Typography from '@material-ui/core/Typography';
|
2020-06-30 14:19:29 +02:00
|
|
|
import Tabs from '@material-ui/core/Tabs';
|
|
|
|
import Tab from '@material-ui/core/Tab';
|
2020-07-09 18:53:51 +02:00
|
|
|
import Box from '@material-ui/core/Box';
|
2020-09-25 13:11:49 +02:00
|
|
|
import { Link } from '@material-ui/core';
|
2020-07-09 18:53:51 +02:00
|
|
|
|
2020-06-30 14:19:29 +02:00
|
|
|
import { useHistory } from "react-router-dom";
|
2020-06-29 23:43:49 +02:00
|
|
|
|
2020-07-09 18:53:51 +02:00
|
|
|
import { useRuleCoverage } from './utils/useRuleCoverage';
|
|
|
|
import { useFetch } from './utils/useFetch';
|
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
2020-07-09 18:53:51 +02:00
|
|
|
ruleBar: {
|
|
|
|
borderBottom: '1px solid lightgrey',
|
|
|
|
},
|
|
|
|
ruleid: {
|
|
|
|
textAlign: 'center',
|
|
|
|
marginTop: theme.spacing(3),
|
|
|
|
marginBottom: theme.spacing(3),
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
textAlign: 'justify',
|
|
|
|
marginTop: theme.spacing(4),
|
|
|
|
marginBottom: theme.spacing(4),
|
|
|
|
},
|
|
|
|
coverage: {
|
|
|
|
marginBottom: theme.spacing(3),
|
|
|
|
},
|
2020-06-29 23:43:49 +02:00
|
|
|
description: {
|
2020-07-09 18:53:51 +02:00
|
|
|
textAlign: 'justify',
|
|
|
|
// marginBottom: theme.spacing(3),
|
2020-06-30 14:19:29 +02:00
|
|
|
},
|
2020-07-09 18:53:51 +02:00
|
|
|
|
|
|
|
// style used to center the tabs when there too few of them to fill the container
|
|
|
|
tabRoot: {
|
|
|
|
justifyContent: "center"
|
2020-06-30 14:19:29 +02:00
|
|
|
},
|
2020-07-09 18:53:51 +02:00
|
|
|
tabScroller: {
|
|
|
|
flexGrow: "0"
|
|
|
|
}
|
2020-06-29 23:43:49 +02:00
|
|
|
}));
|
|
|
|
|
2020-09-25 13:11:49 +02:00
|
|
|
const languageToJiraProject = {
|
|
|
|
"PYTHON": "SONARPY",
|
|
|
|
"ABAP": "SONARABAP",
|
|
|
|
"CFAMILY": "CPP",
|
|
|
|
"JAVA": "SONARJAVA",
|
|
|
|
"COBOL": "SONARCOBOL",
|
|
|
|
"FLEX": "SONARFLEX",
|
|
|
|
"HTML": "SONARHTML",
|
|
|
|
"PHP": "SONARPHP",
|
|
|
|
"PLI": "SONARPLI",
|
|
|
|
"PLSQL": "SONARPLSQL",
|
|
|
|
"RPG": "SONARRPG",
|
|
|
|
"APEX": "SONARSLANG",
|
|
|
|
"RUBY": "SONARSLANG",
|
|
|
|
"KOTLIN": "SONARSLANG",
|
|
|
|
"SCALA": "SONARSLANG",
|
|
|
|
"GO": "SONARSLANG",
|
|
|
|
"SWIFT": "SONARSWIFT",
|
|
|
|
"TSQL": "SONARTSQL",
|
|
|
|
"VB6": "SONARVBSIX",
|
|
|
|
"XML": "SONARXML",
|
|
|
|
};
|
|
|
|
|
|
|
|
const languageToGithubProject = {
|
|
|
|
"ABAP": "sonar-abap",
|
|
|
|
"CSHARP": "sonar-dotnet",
|
|
|
|
"VBNET": "sonar-dotnet",
|
|
|
|
"JAVASCRIPT": "SonarJS",
|
|
|
|
"TYPESCRIPT": "SonarJS",
|
|
|
|
"SWIFT": "sonar-swift",
|
|
|
|
"KOTLIN": "slang-enterprise",
|
|
|
|
"GO": "slang-enterprise",
|
|
|
|
"SCALA": "slang-enterprise",
|
|
|
|
"RUBY": "slang-enterprise",
|
|
|
|
"APEX": "slang-enterprise",
|
|
|
|
"HTML": "sonar-html",
|
|
|
|
"COBOL": "sonar-cobol",
|
|
|
|
"VB6": "sonar-vb",
|
|
|
|
"JAVA": "sonar-java",
|
|
|
|
"PLI": "sonar-pli",
|
|
|
|
"CFAMILY": "sonar-cpp",
|
|
|
|
"CSS": "sonar-css",
|
|
|
|
"PHP": "sonar-php",
|
|
|
|
"PL/SQL": "sonar-plsql",
|
|
|
|
"Python": "sonar-python",
|
|
|
|
"RPG": "sonar-rpg",
|
|
|
|
"Swift": "sonar-swift",
|
|
|
|
"T-SQL": "sonar-tsql",
|
|
|
|
"XML": "sonar-xml",
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
|
|
|
|
export function RulePage(props) {
|
|
|
|
const ruleid = props.match.params.ruleid;
|
|
|
|
const language = props.match.params.language;
|
|
|
|
|
2020-06-30 14:19:29 +02:00
|
|
|
const history = useHistory();
|
|
|
|
function handleLanguageChange(event, lang) {
|
|
|
|
history.push(`/${ruleid}/${lang}`);
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
const classes = useStyles();
|
|
|
|
|
2020-06-30 14:19:29 +02:00
|
|
|
let descUrl = process.env.PUBLIC_URL + '/rules/' + ruleid + "/" + language + "-description.html";
|
|
|
|
let metadataUrl = process.env.PUBLIC_URL + '/rules/' + ruleid + "/" + language + "-metadata.json";
|
2020-07-06 11:03:32 +02:00
|
|
|
let editOnGithubUrl = 'https://github.com/SonarSource/rspec/tree/master/rules/' + ruleid + '/' + language;
|
2020-06-29 23:43:49 +02:00
|
|
|
|
2020-06-30 14:19:29 +02:00
|
|
|
let [descHTML, descError, descIsLoading] = useFetch(descUrl, null, false);
|
|
|
|
let [metadataJSON, metadataError, metadataIsLoading] = useFetch(metadataUrl, null, true);
|
2020-06-29 23:43:49 +02:00
|
|
|
|
2020-07-09 18:53:51 +02:00
|
|
|
const ruleCoverage = useRuleCoverage();
|
|
|
|
let coverage = "Loading...";
|
|
|
|
|
2020-06-30 14:19:29 +02:00
|
|
|
let title = "Loading..."
|
2020-07-06 11:03:32 +02:00
|
|
|
let metadataJSONString;
|
2020-06-30 14:19:29 +02:00
|
|
|
let languagesTabs = null;
|
2020-06-29 23:43:49 +02:00
|
|
|
if (!metadataIsLoading && !metadataError) {
|
2020-06-30 14:19:29 +02:00
|
|
|
title = metadataJSON.title
|
|
|
|
metadataJSON.all_languages.sort()
|
|
|
|
languagesTabs = metadataJSON.all_languages.map(lang => <Tab label={lang} value={lang}/>)
|
2020-07-06 11:03:32 +02:00
|
|
|
metadataJSONString = JSON.stringify(metadataJSON, null, 2);
|
2020-07-09 18:53:51 +02:00
|
|
|
|
|
|
|
coverage = ruleCoverage(language, metadataJSON.allKeys, (key, version) => {
|
|
|
|
return (
|
|
|
|
<li>{key}: {version}</li>
|
|
|
|
)
|
|
|
|
});
|
2020-06-29 23:43:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 09:22:25 +02:00
|
|
|
let description = <div>Loading...</div>;
|
|
|
|
if (!descIsLoading && !descError) {
|
2020-07-06 11:03:32 +02:00
|
|
|
description = <div>
|
|
|
|
<div dangerouslySetInnerHTML={{__html: descHTML}}/>
|
|
|
|
<hr />
|
|
|
|
<a href={editOnGithubUrl}>Edit on Github</a><br/>
|
|
|
|
<hr />
|
|
|
|
<pre>{metadataJSONString}</pre>
|
|
|
|
</div>;
|
2020-06-30 09:22:25 +02:00
|
|
|
}
|
2020-09-25 13:11:49 +02:00
|
|
|
const ruleNumber = ruleid.substring(1)
|
|
|
|
|
|
|
|
const upperCaseLanguage = language.toUpperCase();
|
|
|
|
const jiraProject = languageToJiraProject[upperCaseLanguage];
|
|
|
|
const githubProject = languageToGithubProject[upperCaseLanguage];
|
|
|
|
|
|
|
|
let ticketsLink;
|
|
|
|
if (upperCaseLanguage in languageToJiraProject) {
|
|
|
|
ticketsLink = (
|
|
|
|
<Link href={`https://jira.sonarsource.com/issues/?jql=project%20%3D%20${jiraProject}%20AND%20(text%20~%20%22S${ruleNumber}%22%20OR%20text%20~%20%22RSPEC-${ruleNumber}%22%20OR%20text%20~%20"${title}")`}>
|
|
|
|
Jira Tickets
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ticketsLink = (
|
|
|
|
<Link href={`https://github.com/SonarSource/${githubProject}/issues?q=is%3Aissue+"S${ruleNumber}"+OR+"RSPEC-${ruleNumber}"`}>
|
|
|
|
Github Tickets
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const pullRequestsLink = (
|
|
|
|
<Link href={`https://github.com/SonarSource/${githubProject}/pulls?q=is%3Apr+"S${ruleNumber}"+OR+"RSPEC-${ruleNumber}"`}>
|
|
|
|
Github Pull Requests
|
|
|
|
</Link>
|
|
|
|
);
|
2020-07-09 18:53:51 +02:00
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
return (
|
2020-06-30 14:19:29 +02:00
|
|
|
<div>
|
2020-07-09 18:53:51 +02:00
|
|
|
<div className={classes.ruleBar}>
|
|
|
|
<Container>
|
|
|
|
<Typography variant="h2" classes={{root: classes.ruleid}}>{ruleid}</Typography>
|
2020-06-30 14:19:29 +02:00
|
|
|
<Tabs
|
|
|
|
value={language}
|
|
|
|
onChange={handleLanguageChange}
|
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
|
|
|
centered
|
2020-07-09 18:53:51 +02:00
|
|
|
variant="scrollable"
|
|
|
|
scrollButtons="auto"
|
|
|
|
classes={{ root: classes.tabRoot, scroller: classes.tabScroller }}
|
2020-06-30 14:19:29 +02:00
|
|
|
>
|
|
|
|
{languagesTabs}
|
|
|
|
</Tabs>
|
2020-07-09 18:53:51 +02:00
|
|
|
</Container>
|
|
|
|
</div>
|
2020-06-30 14:19:29 +02:00
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
<Container maxWidth="md">
|
2020-07-09 18:53:51 +02:00
|
|
|
<Typography variant="h3" classes={{root: classes.title}}>{title}</Typography>
|
|
|
|
<Box classes={{root: classes.coverage}}>
|
|
|
|
<Typography variant="h4" >Covered Since</Typography>
|
|
|
|
<ul>
|
|
|
|
{coverage}
|
|
|
|
</ul>
|
|
|
|
</Box>
|
2020-09-25 13:11:49 +02:00
|
|
|
|
|
|
|
<Box classes={{root: classes.coverage}}>
|
|
|
|
<Typography variant="h4" >Related Tickets and Pull Requests</Typography>
|
|
|
|
<ul>
|
|
|
|
{ticketsLink}
|
|
|
|
</ul>
|
|
|
|
<ul>
|
|
|
|
{pullRequestsLink}
|
|
|
|
</ul>
|
|
|
|
</Box>
|
|
|
|
|
2020-07-09 18:53:51 +02:00
|
|
|
<Box classes={{root: classes.description}}>
|
|
|
|
<Typography variant="h4">Description</Typography>
|
|
|
|
<Typography className={classes.description}>
|
|
|
|
{description}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
2020-06-29 23:43:49 +02:00
|
|
|
</Container>
|
2020-06-30 14:19:29 +02:00
|
|
|
</div>
|
2020-07-09 18:53:51 +02:00
|
|
|
|
2020-06-29 23:43:49 +02:00
|
|
|
);
|
2020-07-06 11:03:32 +02:00
|
|
|
}
|