Skip to content

Commit

Permalink
eslintrc: reenable array callback return rule and fix all related errors
Browse files Browse the repository at this point in the history
Reasoning:
A map() creates an array, so a return is expected for all code paths (if/elses).
If one does not want an array or to return data, they should use forEach instead.
Similar for filter().

An expection in our codebase was cockpit.transport.filter which confused
the linter, thinking that its an array filter. I disabled linting on these
lines for this rule.
  • Loading branch information
KKoukiou authored and martinpitt committed Mar 29, 2022
1 parent 9e21fea commit d7c6c14
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"import/no-webpack-loader-syntax": "off",
"object-property-newline": "off",
"react/jsx-no-bind": "off",
"react/jsx-wrap-multilines": "off",
"array-callback-return": "off"
"react/jsx-wrap-multilines": "off"
},
"globals": {
"require": false,
Expand Down
2 changes: 2 additions & 0 deletions pkg/apps/application.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const Application = ({ metainfo_db, id, progress, progress_title, action
{_("View project website")}
</Button>
);
} else {
return null;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions pkg/base1/test-chan.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ QUnit.test("filter message out", function (assert) {

return true;
}
return false;
}, true);

const channel = cockpit.channel({ payload: "null" });
Expand Down
2 changes: 1 addition & 1 deletion pkg/base1/test-dbus-framed.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function parent_window(assert) {
let initialized = false;
let frame;

cockpit.transport.filter((message, channel, control) => {
cockpit.transport.filter((message, channel, control) => { // eslint-disable-line array-callback-return
if (initialized) {
/* Inject an unknown message that gets sent
* before the reply
Expand Down
2 changes: 1 addition & 1 deletion pkg/base1/test-framed.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function parent_window(assert) {
let initialized = false;
let frame;

cockpit.transport.filter(function(message, channel, control) {
cockpit.transport.filter(function (message, channel, control) { // eslint-disable-line array-callback-return
if (initialized)
frame.postMessage(message, cockpit.transport.origin);
});
Expand Down
10 changes: 5 additions & 5 deletions pkg/lib/machine-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const chassis_types = [

function parseDMIFields(text) {
const info = {};
text.split("\n").map(line => {
text.split("\n").forEach(line => {
const sep = line.indexOf(':');
if (sep <= 0)
return;
Expand Down Expand Up @@ -168,15 +168,15 @@ const udevPropertyRE = /^E: (\w+)=(.*)$/;

function parseUdevDB(text) {
const info = {};
text.split("\n\n").map(paragraph => {
text.split("\n\n").forEach(paragraph => {
let syspath = null;
const props = {};

paragraph = paragraph.trim();
if (!paragraph)
return;

paragraph.split("\n").map(line => {
paragraph.split("\n").forEach(line => {
let match = line.match(udevPathRE);
if (match) {
syspath = match[1];
Expand Down Expand Up @@ -212,15 +212,15 @@ const memoryRE = /^([ \w]+): (.*)/;
// Process the dmidecode output and create a mapping of locator to DIMM properties
function parseMemoryInfo(text) {
const info = {};
text.split("\n\n").map(paragraph => {
text.split("\n\n").forEach(paragraph => {
let locator = null;
let bankLocator = null;
const props = {};
paragraph = paragraph.trim();
if (!paragraph)
return;

paragraph.split("\n").map(line => {
paragraph.split("\n").forEach(line => {
line = line.trim();
const match = line.match(memoryRE);
if (match)
Expand Down
4 changes: 4 additions & 0 deletions pkg/networkmanager/firewall.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function serviceRow(props) {
const service = firewall.services[s];
if (service && service.description)
return <li key={service.id}><strong>{service.id}</strong>: {service.description}</li>;
else
return null;
})} </ul></>;
}

Expand Down Expand Up @@ -204,6 +206,8 @@ function ZoneSection(props) {
onRemoveService: service => props.onRemoveService(props.zone.id, service),
readonly: firewall.readonly,
});
} else {
return null;
}
}).concat(
props.zone.ports.length > 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkmanager/network-interface-members.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const NetworkInterfaceMembers = ({
function renderMemberRows() {
const rows = [];

members.map(iface => {
members.forEach(iface => {
const member_con = iface.MainConnection;
const dev = iface.Device;
const isActive = (dev && dev.State == 100 && dev.Carrier === true);
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkmanager/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function ip4_from_text(text, empty_is_zero) {
if (/^[0-9]+$/.test(s.trim()))
return parseInt(s, 10);
else
invalid();
return invalid();
});

let num = 0;
Expand Down
2 changes: 1 addition & 1 deletion pkg/packagekit/updates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function getSeverityURL(urls) {
let highestURL = null;

// search URLs for highest valid severity; by all means we expect an update to have at most one, but for paranoia..
urls.map(value => {
urls.forEach(value => {
if (value.startsWith("https://access.redhat.com/security/updates/classification/#")) {
const i = knownLevels.indexOf(value.slice(value.indexOf("#") + 1));
if (i > highestIndex) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/selinux/selinux-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function init(statusChangedCallback) {
*/

const lines = output.split("\n");
lines.map(function(itm) {
lines.forEach(function(itm) {
const items = itm.trim().split(":");
if (items.length !== 2)
return;
Expand Down
2 changes: 2 additions & 0 deletions pkg/storaged/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ export const CheckBoxes = (tag, title, options) => {
val={fval}
title={field.title}
update_function={fchange} />;
else
return null;
});

if (options.fields.length == 1)
Expand Down
2 changes: 2 additions & 0 deletions pkg/systemd/logDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export class LogEntry extends React.Component {
if (fields.indexOf(p.ID) > 0 || fields.indexOf(p.UUID) || fields.indexOf(p.Duphash)) {
path = p;
return true;
} else {
return false;
}
});

Expand Down
2 changes: 1 addition & 1 deletion pkg/systemd/services/service-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export class ServiceDetails extends React.Component {
const conditions = this.props.unit.Conditions;
const notMetConditions = [];
if (conditions)
conditions.map(condition => {
conditions.forEach(condition => {
if (condition[4] < 0)
notMetConditions.push(cockpit.format(_("Condition $0=$1 was not met"), condition[0], condition[3]));
});
Expand Down

0 comments on commit d7c6c14

Please sign in to comment.