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 52 deletions
Loading
Loading
@@ -18,6 +18,3 @@ export const columnMetricLabel = (state, _getters, _rootState, rootGetters) =>
.find(metric => metric.key === state.columnMetric).label;
 
export const isSelectedSortField = state => sortField => state.sortField === sortField;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const isEmpty = state => !state.rules || !state.rules.length;
export default () => {};
Loading
Loading
@@ -156,5 +156,3 @@ export const setTargetBranch = ({ commit }, targetBranch) =>
commit(types.SET_TARGET_BRANCH, targetBranch);
 
export const undoRulesChange = ({ commit }) => commit(types.UNDO_RULES);
export default () => {};
Loading
Loading
@@ -106,5 +106,3 @@ export const requestDeleteRule = ({ dispatch }, rule) => {
export const addEmptyRule = ({ commit }) => {
commit(types.ADD_EMPTY_RULE);
};
export default () => {};
Loading
Loading
@@ -27,6 +27,3 @@ export const receiveSubscriptionError = ({ commit }) => {
createFlash(__('An error occurred while loading the subscription details.'));
commit(types.RECEIVE_SUBSCRIPTION_ERROR);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const isFreePlan = state => state.plan.code === null;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -28,6 +28,3 @@ export const fetchReport = ({ state, dispatch }) => {
createFlash(s__('ciReport|There was an error fetching the codequality report.'));
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -5,6 +5,3 @@ export const codequalityIssues = state => {
};
 
export const codequalityIssueTotal = state => state.allCodequalityIssues.length;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -304,6 +304,3 @@ export const createEpic = ({ state, dispatch }) => {
dispatch('requestEpicCreateFailure');
});
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -56,6 +56,3 @@ export const isDateInvalid = (state, getters) => {
};
 
export const ancestors = state => (state.ancestors ? [...state.ancestors].reverse() : []);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -73,6 +73,3 @@ export const receiveFeatureFlagError = ({ commit }) => {
};
 
export const toggleActive = ({ commit }, active) => commit(types.TOGGLE_ACTIVE, active);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -105,6 +105,3 @@ export const receiveRotateInstanceIdError = ({ commit }) =>
export const clearAlert = ({ commit }, index) => {
commit(types.RECEIVE_CLEAR_ALERT, index);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -49,6 +49,3 @@ export const receiveCreateFeatureFlagSuccess = ({ commit }) =>
commit(types.RECEIVE_CREATE_FEATURE_FLAG_SUCCESS);
export const receiveCreateFeatureFlagError = ({ commit }, error) =>
commit(types.RECEIVE_CREATE_FEATURE_FLAG_ERROR, error);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -73,5 +73,3 @@ export const setActiveTab = ({ commit, state }, key) => {
export const initChartData = ({ commit }, store) => commit(types.INIT_CHART_DATA, store);
export const setPageLoading = ({ commit }, pageLoading) =>
commit(types.SET_PAGE_LOADING, pageLoading);
export default () => {};
Loading
Loading
@@ -21,6 +21,3 @@ export const fetchChartData = ({ commit, dispatch, getters }, endpoint) => {
.then(() => dispatch('setLoadingState', false))
.catch(() => flash(__('An error occurred while loading chart data')));
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -42,5 +42,3 @@ export const fetchDeleteLicense = ({ state, dispatch }, { id }) => {
dispatch('receiveDeleteLicenseError', { id });
});
};
export default () => {};
// eslint-disable-next-line import/prefer-default-export
export const hasLicenses = state => state.licenses.length > 0;
export default () => {};
Loading
Loading
@@ -71,5 +71,3 @@ export const requestDeletePackage = ({ dispatch, state }, { _links }) => {
createFlash(DELETE_PACKAGE_ERROR_MESSAGE);
});
};
export default () => {};
Loading
Loading
@@ -4,6 +4,7 @@ import createFlash from '~/flash';
import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
import * as types from './mutation_types';
 
// eslint-disable-next-line import/prefer-default-export
export function fetchPage({ commit, state }, newPage) {
return Api.groupMembers(state.groupId, {
with_saml_identity: 'true',
Loading
Loading
@@ -25,5 +26,3 @@ export function fetchPage({ commit, state }, newPage) {
createFlash(__('An error occurred while loading group members.'));
});
}
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
Loading
Loading
@@ -589,6 +589,3 @@ export const fetchProjects = ({ state, dispatch }, searchKey = '') => {
})
.catch(() => dispatch('receiveProjectsFailure'));
};
// 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