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 5 additions and 48 deletions
Loading
Loading
@@ -23,5 +23,3 @@ export const templateTypes = () => [
export const showFileTemplatesBar = (_, getters, rootState) => name =>
getters.templateTypes.find(t => t.name === name) &&
rootState.currentActivityView === leftSidebarViews.edit.name;
export default () => {};
Loading
Loading
@@ -41,5 +41,3 @@ export const fetchMergeRequests = (
};
 
export const resetMergeRequests = ({ commit }) => commit(types.RESET_MERGE_REQUESTS);
export default () => {};
Loading
Loading
@@ -149,5 +149,3 @@ export const resetLatestPipeline = ({ commit }) => {
commit(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, null);
commit(types.SET_DETAIL_JOB, null);
};
export default () => {};
Loading
Loading
@@ -20,5 +20,3 @@ export const failedJobsCount = state =>
);
 
export const jobsCount = state => state.stages.reduce((acc, stage) => acc + stage.jobs.length, 0);
export default () => {};
Loading
Loading
@@ -2,4 +2,3 @@ export * from './setup';
export * from './checks';
export * from './session_controls';
export * from './session_status';
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const allCheck = state => {
const checks = Object.values(state.checks);
 
Loading
Loading
@@ -15,5 +16,3 @@ export const allCheck = state => {
message,
};
};
export default () => {};
Loading
Loading
@@ -128,6 +128,3 @@ export const fetchJobs = ({ state, commit, dispatch }) => {
}
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -247,6 +247,3 @@ export const triggerManualJob = ({ state }, variables) => {
})
.catch(() => flash(__('An error occurred while triggering the job.')));
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -46,6 +46,3 @@ export const isScrollingDown = state => isScrolledToBottom() && !state.isTraceCo
 
export const hasRunnersForProject = state =>
state.job.runners.available && !state.job.runners.online;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -200,6 +200,3 @@ export const dismissRequestLogsError = ({ commit }) => {
export const dismissInvalidTimeRangeWarning = ({ commit }) => {
commit(types.HIDE_TIME_RANGE_INVALID_WARNING);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
import * as types from './mutation_types';
 
// eslint-disable-next-line import/prefer-default-export
export const addModule = ({ commit }, data) => commit(types.ADD_MODULE, data);
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const metricsWithData = (state, getters, rootState, rootGetters) =>
state.modules.map(module => rootGetters[`${module}/metricsWithData`]().length);
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const ADD_MODULE = 'ADD_MODULE';
export default () => {};
Loading
Loading
@@ -682,6 +682,3 @@ export const receiveDeleteDescriptionVersionError = ({ commit }, error) => {
export const updateAssignees = ({ commit }, assignees) => {
commit(types.UPDATE_ASSIGNEES, assignees);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -229,6 +229,3 @@ export const getDiscussion = state => discussionId =>
state.discussions.find(discussion => discussion.id === discussionId);
 
export const commentsDisabled = state => state.commentsDisabled;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -37,6 +37,3 @@ export const receiveSaveChangesError = (_, error) => {
 
createFlash(`${__('There was an error saving your changes.')} ${message}`, 'alert');
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -52,6 +52,3 @@ export const setSelectedSuiteIndex = ({ commit }, data) =>
export const removeSelectedSuiteIndex = ({ commit }) =>
commit(types.SET_SELECTED_SUITE_INDEX, null);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -16,6 +16,3 @@ export const getSuiteTests = state => {
const { test_cases: testCases = [] } = getSelectedSuite(state);
return testCases.sort(sortTestCases).map(addIconStatus);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
import { pickBy } from 'lodash';
import { SUPPORTED_FILTER_PARAMETERS } from './constants';
 
// eslint-disable-next-line import/prefer-default-export
export const validateParams = params => {
return pickBy(params, (val, key) => SUPPORTED_FILTER_PARAMETERS.includes(key) && val);
};
export default () => {};
Loading
Loading
@@ -102,5 +102,3 @@ export const requestDeleteImage = ({ commit }, image) => {
commit(types.SET_MAIN_LOADING, false);
});
};
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