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 4 additions and 24 deletions
Loading
Loading
@@ -17,6 +17,3 @@ export const metrics = state => [
...state.existingMetrics,
...state.removedMetrics.map(metric => ({ ...metric, wasRemoved: true })),
];
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -444,6 +444,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
@@ -163,6 +163,3 @@ export const canCreateMergeRequest = state =>
 
export const canDismissVulnerability = state =>
Boolean(state.createVulnerabilityFeedbackDismissalPath);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -25,5 +25,3 @@ export const fetchDiff = ({ state, rootState, dispatch }) => {
dispatch('receiveDiffError');
});
};
export default () => {};
Loading
Loading
@@ -6,5 +6,3 @@ export const groupedSastText = state =>
 
export const sastStatusIcon = ({ isLoading, hasError, newIssues }) =>
statusIcon(isLoading, hasError, newIssues.length);
export default () => {};
Loading
Loading
@@ -67,5 +67,3 @@ export const generateReportGroup = ({ status = 'some-status', numberOfLicenses =
status,
})),
});
export default () => {};
import { TEST_HOST } from 'spec/test_constants';
 
// eslint-disable-next-line import/prefer-default-export
export const createDraft = () => ({
author: {
id: 1,
Loading
Loading
@@ -23,5 +24,3 @@ export const createDraft = () => ({
isDraft: true,
position: null,
});
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const triggerDOMEvent = type => {
window.document.dispatchEvent(
new Event(type, {
Loading
Loading
@@ -6,5 +7,3 @@ export const triggerDOMEvent = type => {
}),
);
};
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const mockReport = {
status: 'failed',
summary: {
Loading
Loading
@@ -51,5 +52,3 @@ export const mockReport = {
existing_notes: [],
existing_warnings: [],
};
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const adjustMetricQuery = data => {
const updatedMetric = data.metrics;
 
Loading
Loading
@@ -15,6 +16,3 @@ export const adjustMetricQuery = data => {
updatedMetric.queries = queries;
return updatedMetric;
};
// 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