Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

feat: teach "liferay/import-extensions" to check re-exports as well #165

Merged
merged 5 commits into from
Mar 27, 2020

Conversation

wincent
Copy link
Contributor

@wincent wincent commented Mar 27, 2020

See the individual commit messages for details, but in short:

// incorrect code
export {x} from './x.js';

// incorrect code
export {y} from './y';

Required some parser tweaks because the default parser, espree, doesn't handle all of the possible export ... from syntax variants yet.

Closes: #164

wincent added 3 commits March 27, 2020 12:57
Note that two of the test cases are disabled (for now, will fix in the
next commit) because "espree" doesn't handle "export * as name" syntax.

We are using this syntax in one place in liferay-portal right now:

https://github.com/liferay/liferay-portal/blob/1fd785b60f238666c35609f77c2a0d7c605eefdb/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-renderer/src/main/resources/META-INF/resources/index.js#L23

And it works there because we use "babel-eslint" as a parser. It would
also work in Clay where we use `@typescript/eslint-parser`, provided we
keep the dep up-to-date.

Closes: #164
This enables me to uncomment the tests that espree would choke on. Note
that not even the latest release of espree handles this syntax, so
switching to babel-eslint (like we use in portal) or
`@typescript/eslint-parser` is the only way to parse this syntax.

Nevertheless, I don't want to disable the espree tests entirely, so I
extended the MultiTester to run all three parsers, and added support for
a "skip" property that lets us skip the tests that don't run right now
under espree.
Fixes:

  48:5  error  Expected blank line before this statement  padding-line-between-statements
@@ -27,7 +27,8 @@
"author": "Liferay",
"license": "MIT",
"devDependencies": {
"@typescript-eslint/parser": "^2.20.0",
"@typescript-eslint/parser": "^2.25.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update was necessary to handle export * as name syntax with this parser.

parser.run(`${name} (parser: ${key})`, rule, tests);
// Not all tests can run on all parsers, so we filter first.
const handleSkips = test => {
const {skip, ...config} = test;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is no enough to just read skip from the conf; we have to prune it out, otherwise ESLint will yell and scream about an unrecognized property.

With `npx yarn-deduplicate yarn.lock`.

Test plan: `yarn ci`

    Test Suites: 22 passed, 22 total
    Tests:       586 passed, 586 total
    Snapshots:   0 total
    Time:        6.429s
@wincent
Copy link
Contributor Author

wincent commented Mar 27, 2020

I believe these changes are safe, and we have good test coverage in this repo:

Test Suites: 22 passed, 22 total
Tests:       586 passed, 586 total
Snapshots:   0 total
Time:        6.429s

So going to merge.

@wincent wincent merged commit 481a66b into master Mar 27, 2020
@wincent wincent deleted the wincent/extensions branch March 27, 2020 14:20
wincent added a commit to liferay/liferay-npm-tools that referenced this pull request Apr 3, 2020
Release notes:

    https://github.com/liferay/eslint-config-liferay/releases/tag/v20.0.0

Breaking because it includes a new lint:

    liferay/eslint-config-liferay#165

(Not so much a new lint as a additional places where the
"liferay/import-extensions" lint rule now applies.)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Teach "liferay/import-extensions" to check re-exports as well
1 participant