Skip to content

Disable default export rules

Mark Florian requested to merge no-default-export into master

What does this MR do?

Disable default export rules

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

Future iterations will migrate existing default exports to named exports.

Note that a previous version of this MR added eslint-disable import/no-default-export directives, and explicitly disabled that rule. That approach was abandoned for this more iterative approach, since it meant there were over 1,000 changed files!

This bumps to @gitlab/eslint-plugin@4.0.0 to explicitly prefer named exports to default exports (see gitlab-org/frontend/eslint-plugin!22 (merged)).

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

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, to help make it easier to keep this MR up-to-date.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Mark Florian

Merge request reports