Skip to content

Conversation

@devversion
Copy link
Member

  • Checks the added imports for any relative scope imports and automatically suggests the correct Scope Import statement.

Once a forbidden import will be found, we will output a super helpful error message (including suggestion / correction)

image

cc. @jelbourn

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 25, 2016

// Retrieves all scope packages dynamically from the source.
// Developers shouldn't be able to import from other scope packages by using relative paths.
const conpmponentFolders = fs
Copy link

Choose a reason for hiding this comment

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

Should be "componentFolders"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good catch - definitely a cool naming convention :)

* Checks the added imports for any relative scope imports and automatically suggests the correct Scope Import statement.
@jelbourn
Copy link
Member

jelbourn commented Jul 7, 2016

@hansl can you review this one?

const scopePackages = ['src/core'].concat(componentFolders);

const blockedRegex = new RegExp(blocked_statements.join('|'), 'g');
const importRegex = /from '(.*)'/g;
Copy link
Contributor

@hansl hansl Jul 7, 2016

Choose a reason for hiding this comment

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

This doesn't check if the line is an import. What if from '...' is put inside a comment?

There's no cases where you'd have multiple imports on a single line. I suggest the following regex:

const importRegex = /^import.*from\s+'(\S*)';/;

Note that anything else would fail linting, so really this wouldn't be a problem.

@hansl
Copy link
Contributor

hansl commented Jul 7, 2016

LGTM with this note. Please fix and I'll merge. Cheers!

} from '@angular/core';
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/common';
forwardRef
} from '../../core/core';
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was just commited for testing purposes and I already force-pushed to remove it :)

@devversion devversion force-pushed the chore/forbidden-relative-imports branch from 5938be9 to c3127eb Compare July 7, 2016 05:17
@devversion devversion force-pushed the chore/forbidden-relative-imports branch from c3127eb to e9b4da6 Compare July 7, 2016 05:21
@hansl
Copy link
Contributor

hansl commented Jul 7, 2016

LGTM! Let's wait for the tests to pass and I'll merge. Thanks a lot!

@hansl hansl added the pr: lgtm label Jul 7, 2016
@hansl hansl merged commit 819c9ef into angular:master Jul 7, 2016
@devversion devversion deleted the chore/forbidden-relative-imports branch July 7, 2016 05:33
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes PR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants