Skip to content
Snippets Groups Projects
Unverified Commit 78947ddd authored by markrian's avatar markrian
Browse files

Remove no-op default exports

These no-op default exports have served one or both of these purposes:

1. Preventing `babel-plugin-rewire` from generating an invalid default
   during karma tests;
1. Working around the `import/prefer-default-export` ESLint rule for
   files which only have one named export.

As we recently finished migrating all relevant specs from Karma to Jest,
the first purpose is no longer necessary (with two exceptions, see
below).

The second purpose will become unnecessary once the [RFC][1] to prefer
named exports to default exports is implemented.

As such, this commit removes almost all no-op default exports, and adds
explicit `eslint-disable-next-line` directives (which can be removed
once the RFC is implemented).

---

This work was achieved in a few steps. First, the default exports
explicitly marked as `babel-plugin-rewire` workarounds were removed.

This was achieved via this command:

    rg --color=never -l0 "// prevent babel-plugin-rewire" \
        | xargs -0 \
        perl -0pi -e \
        's/\n+\/\/ prevent babel-plugin-rewire[^\n]*tests'\
    '(?:\nexport default \(\) => {};)?//mgs'

The documentation describing this workaround was then removed by hand.

Unfortunately, two files still participate in Karma tests, and still
need this workaround, so these were reverted manually. Those files (at
the time of writing) are:

    app/assets/javascripts/monitoring/stores/actions.js
    app/assets/javascripts/monitoring/stores/getters.js

Then, all additional no-op default exports were removed with this
command:

    rg --color=never -l0 -F "export default () => {};" \
        | xargs -0 perl -0pi -e 's/\n+export default \(\) => {};//mgs'

Since the `import/prefer-default-export` ESLint rule is still in place,
the files violating it have to disable it explicitly.

With the [RFC][1] to prefer named exports to default exports receiving
wide approval, it makes sense to mark these current violations
_explicitly_ with `eslint-disable-next-line` directives, rather than
_implicitly_ via the no-op default export hack.

The benefit of this approach is that when we disable the
`import/prefer-default-export` rule globally for the RFC, ESLint will
warn about all of these now-unnecessary directives. This will make it
much easier to address all of them (perhaps even automatically, via
`--fix`!).

[1]: https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20
parent 149d907c
No related branches found
No related tags found
No related merge requests found
Showing
with 1 addition and 59 deletions
Loading
Loading
@@ -18,6 +18,3 @@ export const itemPathIdSeparator = (state, getters) =>
getters.isEpic ? PathIdSeparator.Epic : PathIdSeparator.Issue;
 
export const isEpic = state => state.issuableType === issuableTypesMap.EPIC;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -345,6 +345,3 @@ export const refreshMilestoneDates = ({ commit, state, getters }) => {
};
 
export const setBufferSize = ({ commit }, bufferSize) => commit(types.SET_BUFFER_SIZE, bufferSize);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -38,6 +38,3 @@ export const timeframeEndDate = (state, getters) => {
endDate.setDate(endDate.getDate() + DAYS_IN_WEEK);
return endDate;
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -45,6 +45,3 @@ export const setToggleValue = ({ commit }, { key, value }) => {
value,
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -18,6 +18,3 @@ export const activeFilters = state => {
};
 
export const visibleFilters = ({ filters }) => filters.filter(({ hidden }) => !hidden);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -188,6 +188,3 @@ export const receiveSearchResultsError = ({ commit }) => {
export const setMinimumQueryMessage = ({ commit }) => {
commit(types.SET_MINIMUM_QUERY_MESSAGE);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -54,6 +54,3 @@ export const receiveProjectsSuccess = ({ commit }, { projects }) => {
export const receiveProjectsError = ({ commit }) => {
commit(types.RECEIVE_PROJECTS_ERROR);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -35,6 +35,3 @@ export const receiveUnscannedProjectsError = ({ commit }) => {
 
commit(RECEIVE_UNSCANNED_PROJECTS_ERROR);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -15,6 +15,3 @@ export const outdatedProjects = ({ projects }) =>
 
export const outdatedProjectsCount = (state, getters) =>
getters.outdatedProjects.reduce((count, currentGroup) => count + currentGroup.projects.length, 0);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -555,6 +555,3 @@ export const openDismissalCommentBox = ({ commit }) => {
export const closeDismissalCommentBox = ({ commit }) => {
commit(types.CLOSE_DISMISSAL_COMMENT_BOX);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -45,5 +45,3 @@ export const isSelectingVulnerabilities = (state, getters) =>
export const hasSelectedAllVulnerabilities = (state, getters) =>
getters.isSelectingVulnerabilities &&
getters.selectedVulnerabilitiesCount === state.vulnerabilities.length;
export default () => {};
Loading
Loading
@@ -38,6 +38,3 @@ export const receiveProjectsError = ({ commit }) => {
 
commit(SET_HAS_ERROR, true);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
import { SEVERITY_GROUPS, SEVERITY_LEVELS_ORDERED_BY_SEVERITY } from './constants';
import { projectsForSeverityGroup, addMostSevereVulnerabilityInformation } from './utils';
 
// eslint-disable-next-line import/prefer-default-export
export const severityGroups = ({ projects }) => {
// add data about it's most severe vulnerability to each project
const projectsWithSeverityInformation = projects.map(
Loading
Loading
@@ -13,6 +14,3 @@ export const severityGroups = ({ projects }) => {
projects: projectsForSeverityGroup(projectsWithSeverityInformation, severityGroup),
}));
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -159,6 +159,3 @@ export const removeIssueFromEpic = ({ state, dispatch }, epic) => {
);
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -45,6 +45,3 @@ export const isDropdownVariantSidebar = state => state.variant === DropdownVaria
* @param {object} state
*/
export const isDropdownVariantStandalone = state => state.variant === DropdownVariant.Standalone;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -198,6 +198,3 @@ export const minimumQueryMessage = ({ commit }) => {
export const setProjects = ({ commit }, projects) => {
commit(types.SET_PROJECTS, projects);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -209,6 +209,3 @@ export const denyLicense = ({ dispatch }, license) => {
dispatch('setLicenseApproval', { license, newStatus: LICENSE_APPROVAL_STATUS.DENIED });
}
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -120,6 +120,3 @@ export const reportContainsBlacklistedLicense = (_, getters) =>
(getters.licenseReport || []).some(
license => license.approvalStatus === LICENSE_APPROVAL_STATUS.DENIED,
);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -21,6 +21,3 @@ export const RECEIVE_LICENSE_CHECK_APPROVAL_RULE_SUCCESS =
'RECEIVE_LICENSE_CHECK_APPROVAL_RULE_SUCCESS';
export const RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR =
'RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR';
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -75,6 +75,3 @@ export const receiveMetricsError = ({ commit, dispatch }) => {
commit(types.RECEIVE_METRICS_ERROR);
dispatch('stopPolling');
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment