Skip to content

Commit

Permalink
Added linting rule preventing one-line-statements without braces
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Wentzel committed Dec 16, 2024
1 parent 33179fe commit c80eb18
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
{
"allowAllPropertiesOnSameLine": true
}
],
"curly": [
"warn",
"all"
]
}
}
10 changes: 8 additions & 2 deletions assets/js/Containers/Databrowser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ class Databrowser extends React.Component {

return primaryFacets.map((key) => {
const value = facets[key];
if (!value) return undefined;
if (!value) {
return undefined;
}

return (
<FacetPanel
value={value}
Expand All @@ -169,7 +172,10 @@ class Databrowser extends React.Component {
})
.map((key) => {
const value = facets[key];
if (!value) return undefined;
if (!value) {
return undefined;
}

return (
<FacetPanel
value={value}
Expand Down
6 changes: 4 additions & 2 deletions assets/js/Containers/FrevaGPT/components/ChatBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class ChatBlock extends React.Component {
}

renderCode(element) {
if (isEmpty(element.content[0])) return null;
else
if (isEmpty(element.content[0])) {
return null;
} else {
return (
<Col md={constants.BOT_COLUMN_STYLE} key={element.content}>
<CodeBlock title={element.variant} code={element.content} />
</Col>
);
}
}

renderUser(element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ function PendingAnswerComponent(props) {

useEffect(() => {
const parsedCode = renderCode(props.content);
if (parsedCode !== "") setRenderedCode(parsedCode);
if (parsedCode !== "") {
setRenderedCode(parsedCode);
}
}, [props.content]);

function renderCode(rawCode) {
let jsonCode = "";
let codeSnippets = "";

if (!rawCode.endsWith('"}')) jsonCode = rawCode + '"}';
else jsonCode = rawCode;
if (!rawCode.endsWith('"}')) {
jsonCode = rawCode + '"}';
} else {
jsonCode = rawCode;
}

try {
const code = JSON.parse(jsonCode);
Expand Down
19 changes: 14 additions & 5 deletions assets/js/Containers/FrevaGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class FrevaGPT extends React.Component {

try {
const response = await fetch("/api/chatbot/ping");
if (response.status === 200) pingSuccessful = true;
if (response.status === 200) {
pingSuccessful = true;
}
} catch (err) {
console.error("PingError: ", err);
}
Expand All @@ -101,7 +103,9 @@ class FrevaGPT extends React.Component {
if (await successfulPing()) {
this.setState({ botOkay: true });
await getBotModels();
} else this.setState({ botOkay: false });
} else {
this.setState({ botOkay: false });
}
}

createNewChat() {
Expand Down Expand Up @@ -174,7 +178,9 @@ class FrevaGPT extends React.Component {
while (true) {
// eslint-disable-next-line no-await-in-loop
const { done, value } = await reader.read();
if (done) break;
if (done) {
break;
}

const decodedValues = decoder.decode(value);
buffer = buffer + decodedValues;
Expand All @@ -185,7 +191,9 @@ class FrevaGPT extends React.Component {
foundSomething = false;

for (let bufferIndex = 0; bufferIndex < buffer.length; bufferIndex++) {
if (buffer[bufferIndex] !== "}") continue;
if (buffer[bufferIndex] !== "}") {
continue;
}
const subBuffer = buffer.slice(0, bufferIndex + 1);

try {
Expand Down Expand Up @@ -250,8 +258,9 @@ class FrevaGPT extends React.Component {
if (
!subBuffer.includes("ServerHint") &&
!subBuffer.includes("Code")
)
) {
console.error(err);
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions assets/js/Containers/FrevaGPT/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export function formatCode(mode, data) {
let rawCode;

try {
if (mode === "Code") rawCode = JSON.parse(shortData).code;
else if (mode === "CodeOutput") rawCode = shortData;
if (mode === "Code") {
rawCode = JSON.parse(shortData).code;
} else if (mode === "CodeOutput") {
rawCode = shortData;
}
codeSnippets = rawCode.split("\\n");
} catch (err) {
// do something
Expand Down

0 comments on commit c80eb18

Please sign in to comment.