Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed bug in old parser when using the defaults #200

Merged
merged 9 commits into from
Nov 9, 2020

Conversation

WillieRuemmele
Copy link
Member

What does this PR do?

the default ignore lines we use with the new parser had a bug with the old parser. Specifically the **/*.dup* was being exploded to ignore any item containing "dup" which for the metadata type DuplicateRule caused an issue

fixed analytics to log the lines that caused the issue, and the file path

What issues does this PR fix or reference?

forcedotcom/cli#685
@W-8291520@

Functionality Before

<insert gif and/or summary>

Functionality After

<insert gif and/or summary>

@WillieRuemmele WillieRuemmele requested a review from a team as a code owner November 2, 2020 23:15
shetzel
shetzel previously requested changes Nov 3, 2020
@@ -81,7 +80,7 @@ export class ForceIgnore {
denies = this.parser.ignores(relativePath);
fctResult = this.gitignoreParser.denies(relativePath);
// send to look for differences, analytics
this.resolveConflict(denies, fctResult, this.contents);
this.resolveConflict(denies, fctResult, this.contents, relativePath);
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's an instance var you don't have to pass it to a method that has access to that instance var.

If we're passing the relativePath here then we don't need to do the relative path resolution in resolveConflict

@@ -150,7 +150,7 @@ export class ForceIgnore {
// send analytics, if they exist.
Lifecycle.getInstance().emit('telemetry', {
eventName: 'FORCE_IGNORE_DIFFERENCE',
content: this.contents,
content,
oldLibraryResults,
newLibraryResults,
ignoreLines: this.ignoreLines,
Copy link
Contributor

Choose a reason for hiding this comment

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

this.ignoreLines will always be the entire contents of the forceignore file. don't we want this to only report the specific rules that caused the conflict?

Copy link
Member Author

Choose a reason for hiding this comment

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

it was only the entries which caused issues... I renamed the variable to be more clear about what it is

@@ -122,6 +121,7 @@ export class ForceIgnore {
private resolveConflict(
newLibraryResults: boolean,
oldLibraryResults: boolean,
content: string,
file: string
Copy link
Contributor

Choose a reason for hiding this comment

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

newLibraryResults and oldLibraryResults are very clear. content and file aren't. The content arg doesn't seem necessary since it's always this.contents. Can we name those so it's clearer? E.g., forceignoreContents (if you keep it) and sourceFilePath?

@brpowell
Copy link
Contributor

brpowell commented Nov 4, 2020

Revert these files please:

  • Code owners
  • .gitignore
  • snippets.code-snippets
  • CHANGELOG
  • Coding-guidelines
  • commit-guidelines

// only show the warning once, it could come from denies() or accepts()
warn = false;
process.emitWarning(
"The .forceignore file doesn't adhere to .gitignore format which will be the default behavior starting in Spring '21 release. More information on .gitignore format here: https://git-scm.com/docs/gitignore. Fix the following lines in your .forceignore and add '# .forceignore v2' to your .forceignore file to switch to the new behavior."
"The .forceignore sourceFilePath doesn't adhere to .gitignore format which will be the default behavior starting in Spring '21 release. More information on .gitignore format here: https://git-scm.com/docs/gitignore. Fix the following lines in your .forceignore and add '# .forceignore v2' to your .forceignore sourceFilePath to switch to the new behavior."
Copy link
Contributor

Choose a reason for hiding this comment

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

should this say sourceFilePath?

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, I refactored a variable name and it didn't work correctly... look at all of the files I changed ( even though I didn't add them to my commit ) I'm going back through everything to make sure it's as it should be

): void {
const ignoreItems = this.contents.split('\n');
const troubledIgnoreLines: string[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a Set<string> for troubledIgnoreLines and on line 136 use has instead of includes so we don't have to iterate through the whole list each time to test for membership.

@@ -122,29 +120,28 @@ export class ForceIgnore {
private resolveConflict(
newLibraryResults: boolean,
oldLibraryResults: boolean,
file: string
sourceFilePath: string
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fsPath has somewhat been a codebase convention for "file path" if you're looking to rename this, nbd though.

'**/package2-descriptor.json',
'**/package2-manifest.json',
],
ignoreLines: [testPattern],
file,
};

const telemetrySpy = env.spy(Lifecycle.prototype, 'emit');
// @ts-ignore call the private method directly to avoid excessive stubbing
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what would need to be excessively stubbed?

Copy link
Member Author

Choose a reason for hiding this comment

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

At this point it might not require a lot of stubbing

Copy link
Contributor

Choose a reason for hiding this comment

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

If not much is needed then forceIgnore.accept or forceIgnore.deny is preferred over forceIgnore.resolveConflict(true, false, file)

@@ -153,8 +156,8 @@ export class ForceIgnore {
content: this.contents,
oldLibraryResults,
newLibraryResults,
ignoreLines: this.ignoreLines,
file,
ignoreLines,
Copy link
Contributor

@brpowell brpowell Nov 5, 2020

Choose a reason for hiding this comment

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

Can remove 147-151 and use this instead - easy way to convert an iterable to array.

Suggested change
ignoreLines,
ignoreLines: Array.from(troubledIgnoreLines),

Copy link
Member Author

Choose a reason for hiding this comment

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

BOOM 💥

@brpowell brpowell removed the request for review from shetzel November 9, 2020 17:38
@brpowell brpowell dismissed shetzel’s stale review November 9, 2020 17:39

changes were addressed and steve is out for the day.

@WillieRuemmele WillieRuemmele merged commit 3ccbfa8 into develop Nov 9, 2020
@WillieRuemmele WillieRuemmele deleted the wr/fixDefaultIgnore branch November 9, 2020 18:23
brpowell pushed a commit that referenced this pull request Nov 12, 2020
* fix: The old parser had a bug when handling the new default values
brpowell pushed a commit that referenced this pull request Nov 12, 2020
* fix: The old parser had a bug when handling the new default values
sfsholden pushed a commit that referenced this pull request May 6, 2021
* fix: The old parser had a bug when handling the new default values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants