web/src/pages/Home/CourtOverview/Chart.tsx
Function Chart
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const Chart: React.FC = () => {
const [chartOption, setChartOption] = useState("stakedPNK");
const { data } = useHomePageContext();
const chartData = data?.counters;
const courtsChartData = data?.courts;
- Create a ticketCreate a ticket
Function Chart
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
Open
const Chart: React.FC = () => {
const [chartOption, setChartOption] = useState("stakedPNK");
const { data } = useHomePageContext();
const chartData = data?.counters;
const courtsChartData = data?.courts;
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Assigning this
reference to local variable not allowed: tooltip. Open
Open
const tooltip = this;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Rule: no-this-assignment
Disallows unnecessary references to this
.
Rationale
Assigning a variable to this
instead of properly using arrow lambdas may be a symptom of pre-ES6 practices
or not managing scope well.
Instead of storing a reference to this
and using it inside a function () {
:
const self = this;
setTimeout(function () {
self.doWork();
});
Use () =>
arrow lambdas, as they preserve this
scope for you:
setTimeout(() => {
this.doWork();
});
Config
Two options may be provided on an object:
-
allow-destructuring
allows using destructuring to access members ofthis
(e.g.{ foo, bar } = this;
). -
allowed-names
may be specified as a list of regular expressions to match allowed variable names.
Examples
"no-this-assignment": true
"no-this-assignment": true,[object Object]
Schema
{
"additionalProperties": false,
"properties": {
"allow-destructuring": {
"type": "boolean"
},
"allowed-names": {
"listType": "string",
"type": "list"
}
},
"type": "object"
}
For more information see this page.