Commit 600155b6 authored by Mark Florian's avatar Mark Florian

Disable default export rules

This is part of the work to implement the consensus reached in the
[RFC][1] to prefer named exports over defalt exports.

Future iterations will migrate existing default exports to named
exports.

The bulk of the changes in this commit were performed with the following
script:

```bash
set -u

changed-files()
{
    local trunk="origin/master"
    local file=
    local committed_files=$(git diff "$trunk"... --numstat \
        | awk '/\.(js|vue)$/{ print $3 }')
    local changed_files=$(git diff --numstat \
        | awk '/\.(js|vue)$/{ print $3 }')
    for file in ${committed_files[@]} ${changed_files[@]}; do
        if [ -f "$file" ]; then
            echo "$file"
        fi
    done
}

git grep -lz "import/prefer-default-export" -- '**/*.js' \
    | xargs -0 perl -0pi -e \
    "s/[^\n]*eslint-disable[^\n]*"\
"import\/prefer-default-export[^\n]*\n//mgs"

git grep -lz "rfcs/-/issues/20" -- '**/*.js' \
    | xargs -0 perl -0pi -e \
    "s/[^\n]*rfcs\/-\/issues\/20[^\n]*\n//mgs"

yarn prettier --write $(changed-files)
```

The script is [idempotent][2], to help make it easier to keep
up-to-date.

[1]: https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20
[2]: https://en.wikipedia.org/wiki/Idempotence
parent 53814371
......@@ -17,6 +17,7 @@ settings:
config: './config/webpack.config.js'
rules:
import/no-commonjs: error
import/no-default-export: off
no-underscore-dangle:
- error
- allow:
......
......@@ -3,7 +3,6 @@
* and returns an array of the following form:
* [{ key: "forks", label: "Forks", value: 50 }]
*/
// eslint-disable-next-line import/prefer-default-export
export const getStatistics = state => labels =>
Object.keys(labels).map(key => {
const result = {
......
......@@ -3,7 +3,6 @@ import { mapActions } from 'vuex';
import store from '~/mr_notes/stores';
import ReviewBar from './components/review_bar.vue';
// eslint-disable-next-line import/prefer-default-export
export const initReviewBar = () => {
const el = document.getElementById('js-review-bar');
......
import { __ } from '~/locale';
// eslint-disable import/prefer-default-export
export const ADD_CI_VARIABLE_MODAL_ID = 'add-ci-variable';
export const displayText = {
......
/* eslint-disable import/prefer-default-export */
// Disabling import/prefer-default-export can be
// removed once a second getter is added to this file
import { uniq } from 'lodash';
export const joinedEnvironments = state => {
......
......@@ -3,7 +3,6 @@ import { __ } from '~/locale';
import service from '../services/contributors_service';
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const fetchChartData = ({ commit }, endpoint) => {
commit(types.SET_LOADING_STATE, true);
......
// eslint-disable-next-line import/prefer-default-export
export const KUBERNETES_VERSIONS = [{ name: '1.14', value: '1.14' }];
// eslint-disable-next-line import/prefer-default-export
export const subnetValid = ({ selectedSubnet }) =>
Array.isArray(selectedSubnet) && selectedSubnet.length >= 2;
......@@ -5,7 +5,6 @@ const DESIGN_TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/design_management_contex
const DESIGN_TRACKING_PAGE_NAME = 'projects:issues:design';
const DESIGN_TRACKING_EVENT_NAME = 'view_design';
// eslint-disable-next-line import/prefer-default-export
export function trackDesignDetailView(
referer = '',
owner = '',
......
......@@ -5,7 +5,6 @@ const DESIGN_TRACKING_CONTEXT_SCHEMA = 'iglu:com.gitlab/design_management_contex
const DESIGN_TRACKING_PAGE_NAME = 'projects:issues:design';
const DESIGN_TRACKING_EVENT_NAME = 'view_design';
// eslint-disable-next-line import/prefer-default-export
export function trackDesignDetailView(
referer = '',
owner = '',
......
......@@ -18,7 +18,6 @@ function fileSymlinkInformation(file, fileList) {
);
}
/* eslint-disable-next-line import/prefer-default-export */
export function prepareRawDiffFile({ file, allFiles }) {
Object.assign(file, {
brokenSymlink: fileSymlinkInformation(file, allFiles),
......
......@@ -11,9 +11,6 @@
* @typedef {String} UUIDv4
*/
// https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20
/* eslint-disable import/prefer-default-export */
import MersenneTwister from 'mersenne-twister';
import stringHash from 'string-hash';
import { isString } from 'lodash';
......
......@@ -4,5 +4,4 @@
* @param {Object} environment
* @returns {Object}
*/
// eslint-disable-next-line import/prefer-default-export
export const setDeployBoard = (oldEnvironmentState, environment) => environment;
......@@ -10,7 +10,6 @@ const stopPolling = poll => {
if (poll) poll.stop();
};
// eslint-disable-next-line import/prefer-default-export
export function startPollingStacktrace({ commit }, endpoint) {
stackTracePoll = new Poll({
resource: service,
......
// eslint-disable-next-line import/prefer-default-export
export const stacktrace = state =>
state.stacktraceData.stack_trace_entries
? state.stacktraceData.stack_trace_entries.reverse()
......
// eslint-disable-next-line import/prefer-default-export
export const hasSearchQuery = state => state.searchQuery !== '';
......@@ -33,7 +33,6 @@ const EmptyRouterComponent = {
},
};
// eslint-disable-next-line import/prefer-default-export
export const createRouter = store => {
const router = new IdeRouter({
mode: 'history',
......
import { diffLines } from 'diff';
import { defaultDiffOptions } from '../editor_options';
// See: https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20
// eslint-disable-next-line import/prefer-default-export
export const computeDiff = (originalContent, newContent) => {
// prevent EOL changes from highlighting the entire file
const changes = diffLines(
......
......@@ -42,7 +42,6 @@ function getRulesWithConfigs(filePath, configFiles = [], rules = {}) {
return isRoot ? result : getRulesWithConfigs(filePath, nextConfigs, result);
}
// eslint-disable-next-line import/prefer-default-export
export function getRulesWithTraversal(filePath, getFileContent) {
const editorconfigPaths = [
...getPathParents(filePath).map(x => `${x}/.editorconfig`),
......
......@@ -17,5 +17,4 @@ const getClient = memoize(() =>
),
);
// eslint-disable-next-line import/prefer-default-export
export const query = (...args) => getClient().query(...args);
// eslint-disable-next-line import/prefer-default-export
export const isAliveView = state => view =>
state.keepAliveViews[view] || (state.isOpen && state.currentView === view);
// eslint-disable-next-line import/prefer-default-export
export const states = {
failed: 'failed',
};
// eslint-disable-next-line import/prefer-default-export
export const normalizeJob = job => ({
id: job.id,
name: job.name,
......
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const push = ({ commit }, fullPath) => {
commit(types.PUSH, fullPath);
};
// eslint-disable-next-line import/prefer-default-export
export const PUSH = 'PUSH';
// eslint-disable-next-line import/prefer-default-export
export const allCheck = state => {
const checks = Object.values(state.checks);
......
/* eslint-disable import/prefer-default-export */
/**
* This method adds listeners to the given router and store and syncs their state with eachother
*
......
import { STATUSES } from './constants';
// Will be expanded in future
// eslint-disable-next-line import/prefer-default-export
export function isProjectImportable(project) {
return project.importStatus === STATUSES.NONE && !project.importSource.incompatible;
}
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const setOverride = ({ commit }, override) => commit(types.SET_OVERRIDE, override);
......@@ -7,7 +7,6 @@ import createState from './state';
Vue.use(Vuex);
// eslint-disable-next-line import/prefer-default-export
export const createStore = (initialState = {}) =>
new Vuex.Store({
actions,
......
// eslint-disable-next-line import/prefer-default-export
export const SET_OVERRIDE = 'SET_OVERRIDE';
......@@ -3,7 +3,6 @@ import { __ } from '~/locale';
/**
* Returns the attributes used for gl-empty-state in the Service Desk issues list.
*/
// eslint-disable-next-line import/prefer-default-export
export function emptyStateHelper(emptyStateMeta) {
const { isServiceDeskSupported, svgPath, serviceDeskHelpPage } = emptyStateMeta;
......
/* eslint-disable import/prefer-default-export */
export function isImageLoaded(element) {
return element.complete && element.naturalHeight !== 0;
}
......@@ -4,6 +4,5 @@
* @param {Set} superset The set to be considered as the superset.
* @returns {boolean}
*/
// eslint-disable-next-line import/prefer-default-export
export const isSubset = (subset, superset) =>
Array.from(subset).every(value => superset.has(value));
// eslint-disable-next-line import/prefer-default-export
export const isObject = obj => obj && obj.constructor === Object;
import { joinPaths } from '~/lib/utils/url_utility';
// tell webpack to load assets from origin so that web workers don't break
// eslint-disable-next-line import/prefer-default-export
export function resetServiceWorkersPublicPath() {
// __webpack_public_path__ is a global variable that can be used to adjust
// the webpack publicPath setting at runtime.
......
......@@ -125,7 +125,6 @@ const csvData = (metricHeaders, metricValues) => {
* @param {Object} graphData - Panel contents
* @returns {String}
*/
// eslint-disable-next-line import/prefer-default-export
export const graphDataToCsv = graphData => {
const delimiter = ',';
const br = '\r\n';
......
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const addModule = ({ commit }, data) => commit(types.ADD_MODULE, data);
// eslint-disable-next-line import/prefer-default-export
export const metricsWithData = (state, getters, rootState, rootGetters) =>
state.modules.map(module => rootGetters[`${module}/metricsWithData`]().length);
// eslint-disable-next-line import/prefer-default-export
export const ADD_MODULE = 'ADD_MODULE';
/* eslint-disable import/prefer-default-export */
export const FILTERED_SEARCH = {
MERGE_REQUESTS: 'merge_requests',
ISSUES: 'issues',
......
/* eslint-disable import/prefer-default-export */
export const ISSUABLE_INDEX = {
MERGE_REQUEST: 'merge_request_',
ISSUE: 'issue_',
......
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);
};
......@@ -7,7 +7,6 @@ import state from './state';
Vue.use(Vuex);
// eslint-disable-next-line import/prefer-default-export
export const createStore = () =>
new Vuex.Store({
state,
......
// eslint-disable-next-line import/prefer-default-export
export const decodeAndParse = param => JSON.parse(window.atob(param));
import { LOADING, ERROR, SUCCESS, STATUS_FAILED } from '../constants';
// eslint-disable-next-line import/prefer-default-export
export const summaryStatus = state => {
if (state.isLoading) {
return LOADING;
......
// eslint-disable-next-line import/prefer-default-export
export function normalizeData(data, path, extra = () => {}) {
return data.map(d => ({
sha: d.commit.id,
......
......@@ -88,7 +88,6 @@ const fileTypeIcons = [
},
];
// eslint-disable-next-line import/prefer-default-export
export const getIconName = (type, path) => {
if (entryTypeIcons[type]) return entryTypeIcons[type];
......
......@@ -28,5 +28,4 @@ const isPlainReadme = file => {
return re.test(file.name);
};
// eslint-disable-next-line import/prefer-default-export
export const readmeFile = blobs => blobs.find(isRichReadme) || blobs.find(isPlainReadme);
......@@ -2,7 +2,6 @@ import GetSnippetQuery from '../queries/snippet.query.graphql';
const blobsDefault = [];
// eslint-disable-next-line import/prefer-default-export
export const getSnippetMixin = {
apollo: {
snippet: {
......
// eslint-disable-next-line import/prefer-default-export
export const getBinary = file => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
......
import { s__, n__ } from '~/locale';
// eslint-disable-next-line import/prefer-default-export
export const title = state => {
if (state.isLoading) {
return s__('BuildArtifacts|Loading artifacts');
......
// eslint-disable-next-line import/prefer-default-export
export const stripQuotes = value => {
return value.includes(' ') ? value.slice(1, -1) : value;
};
/* eslint-disable import/prefer-default-export */
function trimFirstCharOfLineContent(text) {
if (!text) {
return text;
......
......@@ -9,7 +9,6 @@
* @param {string} root - the key of the state where to search fo they keys described in list
* @returns {Object} a dictionary with all the computed properties generated
*/
// eslint-disable-next-line import/prefer-default-export
export const mapComputed = (list, defaultUpdateFn, root) => {
const result = {};
list.forEach(item => {
......
......@@ -55,10 +55,6 @@ export const createStore = () =>
});
```
_Note:_ Until this
[RFC](https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20) is implemented,
the above will need to disable the `import/prefer-default-export` ESLint rule.
### `state.js`
The first thing you should do before writing any code is to design the state.
......
// eslint-disable-next-line import/prefer-default-export
export const customStageFormActive = ({ isCreatingCustomStage, isEditingCustomStage }) =>
Boolean(isCreatingCustomStage || isEditingCustomStage);
......@@ -18,7 +18,6 @@ import { dateFormats } from '../shared/constants';
*
* @return {Array} the computed month data
*/
// eslint-disable-next-line import/prefer-default-export
export const computeMonthRangeData = (startDate, endDate, format = dateFormats.isoDate) => {
const monthData = [];
const monthNames = getMonthNames(true);
......
import SET_ENDPOINT from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const setEndpoint = ({ commit }, endpoint) => commit(SET_ENDPOINT, endpoint);
// eslint-disable-next-line import/prefer-default-export
export const getMetricTypes = state => chartKey =>
state.metricTypes.filter(m => m.charts.indexOf(chartKey) !== -1);
// eslint-disable-next-line import/prefer-default-export
export const isEmpty = state => !state.rules || !state.rules.length;
// eslint-disable-next-line import/prefer-default-export
export const isFreePlan = state => state.plan.code === null;
// Limit the number of vulnerabilities to display so as to avoid jank.
// In practice, this limit will probably never be reached, since the
// largest number of vulnerabilities we've seen one dependency have is 20.
// eslint-disable-next-line import/prefer-default-export
export const MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY = 50;
import { s__ } from '~/locale';
import { FILTER } from './modules/list/constants';
// eslint-disable-next-line import/prefer-default-export
export const DEPENDENCY_LIST_TYPES = {
all: {
namespace: 'allDependencies',
......
import listModule from './modules/list';
// eslint-disable-next-line import/prefer-default-export
export const addListType = (store, listType) => {
const { initialState, namespace } = listType;
store.registerModule(namespace, listModule());
......
......@@ -4,7 +4,6 @@
* @param {Object} environment
* @returns {Object}
*/
// eslint-disable-next-line import/prefer-default-export
export const setDeployBoard = (oldEnvironmentState, environment) => {
let parsedEnvironment = environment;
if (environment.size === 1 && environment.rollout_status) {
......
/* eslint-disable import/prefer-default-export */
import { USER_TOKEN_TYPES as CE_USER_TOKEN_TYPES } from '~/filtered_search/constants';
export const USER_TOKEN_TYPES = [...CE_USER_TOKEN_TYPES, 'approver', 'approved-by'];
// eslint-disable-next-line import/prefer-default-export
export const formHasError = state => Object.values(state.formErrors).some(val => Boolean(val));
// eslint-disable-next-line import/prefer-default-export
export const replicableTypeName = state => state.replicableType.split('_').join(' ');
......@@ -7,7 +7,6 @@ import createGqClient, { fetchPolicies } from '~/lib/graphql';
think the sync process is broken.
*/
// eslint-disable-next-line import/prefer-default-export
export const gqClient = createGqClient(
{},
{
......
// eslint-disable-next-line import/prefer-default-export
export const formHasError = state =>
Object.keys(state.formErrors)
.map(key => state.formErrors[key])
......
......@@ -7,7 +7,6 @@
*
* @returns {Object} the transformed filters for the public api
*/
// eslint-disable-next-line import/prefer-default-export
export const transformFilters = ({
label_name: labels = null,
milestone_title: milestone = null,
......
/* eslint-disable import/prefer-default-export */
export const LICENSE_LIST = 'licenseList';
// eslint-disable-next-line import/prefer-default-export
export const hasLicenses = state => state.licenses.length > 0;
/* eslint-disable import/prefer-default-export */
export const SCAN_TYPES = {
PASSIVE: 'PASSIVE',
};
......@@ -4,7 +4,6 @@ import { deprecatedCreateFlash as 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',
......
// eslint-disable-next-line import/prefer-default-export
export const RECEIVE_SAML_MEMBERS_SUCCESS = 'RECEIVE_SAML_MEMBERS_SUCCESS';
/* eslint-disable import/prefer-default-export */
/**
*
* Sets the text content of a DOM element to a given value.
......
import { normalizeData as normalizeDataFOSS } from '~/repository/utils/commit';
// eslint-disable-next-line import/prefer-default-export
export function normalizeData(data, path) {
return normalizeDataFOSS(data, path, d => ({
lockLabel: d.lock_label || false,
......
......@@ -2,7 +2,6 @@ import * as Sentry from '@sentry/browser';
import axios from '~/lib/utils/axios_utils';
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const fetchSecurityConfiguration = ({ commit, state }) => {
if (!state.securityConfigurationPath) {
return commit(types.RECEIVE_SECURITY_CONFIGURATION_ERROR);
......
/* eslint-disable import/prefer-default-export */
export const COLLAPSE_SECURITY_REPORTS_SUMMARY_LOCAL_STORAGE_KEY =
'hide_pipelines_security_reports_summary_details';
/* eslint-disable import/prefer-default-export */
export const FUZZING_STAGE = 'fuzz';
/* eslint-disable import/prefer-default-export */
import { getDayDifference, isValidDate } from '~/lib/utils/datetime_utility';
/**
......
/* eslint-disable import/prefer-default-export */
import { isEqual } from 'lodash';
const isVulnerabilityLike = object =>
......
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(
......
/* eslint-disable import/prefer-default-export */
import { PREDEFINED_NETWORK_POLICIES } from 'ee/threat_monitoring/constants';
export const policiesWithDefaults = ({ policies }) => {
......
// eslint-disable-next-line import/prefer-default-export
export const hasHistory = ({ statistics: { history } }) =>
Boolean(history.nominal.length || history.anomalous.length);
// eslint-disable-next-line import/prefer-default-export
export const DropdownVariant = {
Sidebar: 'sidebar',
Standalone: 'standalone',
......
/* eslint-disable import/prefer-default-export */
export const LICENSE_MANAGEMENT = 'licenseManagement';
import subscriptionState from 'ee/billings/stores/modules/subscription/state';
// eslint-disable-next-line import/prefer-default-export
export const resetStore = store => {
const newState = {
subscription: subscriptionState(),
......
// eslint-disable-next-line import/prefer-default-export
export const makeDependency = (changes = {}) => ({
name: 'left-pad',
version: '0.0.3',
......
// eslint-disable-next-line import/prefer-default-export
export const makeLicense = (changes = {}) => ({
name: 'Apache 2.0',
url: 'http://www.apache.org/licenses/LICENSE-2.0.txt',
......
// eslint-disable-next-line import/prefer-default-export
export const generateFeatures = (n, overrides = {}) => {
return [...Array(n).keys()].map(i => ({
type: `scan-type-${i}`,
......
......@@ -7,7 +7,6 @@
* generated entities.
* @returns {Object[]}
*/
// eslint-disable-next-line import/prefer-default-export
export const makeEntities = (count, changes) =>
[...Array(count).keys()].map(i => ({
defaultValue: `defaultValue${i}`,
......
import vulnerabilitiesState from 'ee/security_dashboard/store/modules/vulnerabilities/state';
import filterState from 'ee/security_dashboard/store/modules/filters/state';
// eslint-disable-next-line import/prefer-default-export
export const resetStore = store => {
const newState = {
vulnerabilities: vulnerabilitiesState(),
......
import { TEST_HOST } from 'spec/test_constants';
// eslint-disable-next-line import/prefer-default-export
export const createDraft = () => ({
author: {
id: 1,
......
/* eslint-disable import/prefer-default-export */
/* https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20 */
export const diffMetadata = {
real_size: '1',
size: 1,
......
// eslint-disable-next-line import/prefer-default-export
export const triggerDOMEvent = type => {
window.document.dispatchEvent(
new Event(type, {
......
// eslint-disable-next-line import/prefer-default-export
export const useFakeRequestAnimationFrame = () => {
let orig;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment