Skip to content

Commit

Permalink
chore: fix forceignore warnings on commented lines
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Nov 26, 2024
1 parent 7e75dd5 commit 8ee12bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/resolve/forceIgnore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { dirname, join, relative } from 'node:path';
import * as os from 'node:os';
import ignore, { Ignore } from 'ignore/index';
import { readFileSync } from 'graceful-fs';
import { Lifecycle } from '@salesforce/core';
Expand All @@ -24,8 +25,8 @@ export class ForceIgnore {
const contents = readFileSync(forceIgnorePath, 'utf-8');
// check if file `.forceignore` exists
if (contents !== undefined) {
// check for windows style separators (\) and warn
if (contents.includes('\\')) {
// check for windows style separators (\) and warn, that aren't comments
if (contents.split(os.EOL).find((c) => c.includes('\\') && !c.startsWith('#'))) {
// void because you cannot await a method in a constructor
void Lifecycle.getInstance().emitWarning(
'Your .forceignore file incorrectly uses the backslash ("\\") as a folder separator; it should use the slash ("/") instead. The ignore rules will not work as expected until you fix this.'
Expand Down
14 changes: 14 additions & 0 deletions test/resolve/forceIgnore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { join } from 'node:path';
import * as os from 'node:os';
import { expect } from 'chai';
import { createSandbox } from 'sinon';
import fs from 'graceful-fs';
Expand Down Expand Up @@ -47,6 +48,19 @@ describe('ForceIgnore', () => {
expect(lifecycleStub.callCount).to.equal(1);
});

it('will not warn for \\ on commented lines', () => {
const lifecycleStub = env.stub(Lifecycle.prototype, 'emitWarning');
const forceIgnoreEntry = `# force-app\\main\\default\\classes\\myApex.* ${os.EOL} force-app\\main\\default\\classes\\myApex.*`;
const pathToClass = join('force-app', 'main', 'default', 'classes', 'myApex.cls');
env.stub(fs, 'readFileSync').returns(forceIgnoreEntry);

const forceIgnore = new ForceIgnore();

expect(forceIgnore.accepts(pathToClass)).to.be.true;
// once, second line is uncommented, but uses \
expect(lifecycleStub.callCount).to.equal(1);
});

it('Should find a forceignore file from a given path', () => {
const readStub = env.stub(fs, 'readFileSync');
const searchStub = env.stub(fsUtil, 'searchUp');
Expand Down

2 comments on commit 8ee12bc

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 8ee12bc Previous: 4b31051 Ratio
eda-componentSetCreate-linux 212 ms 210 ms 1.01
eda-sourceToMdapi-linux 1959 ms 1917 ms 1.02
eda-sourceToZip-linux 1753 ms 1706 ms 1.03
eda-mdapiToSource-linux 2641 ms 2602 ms 1.01
lotsOfClasses-componentSetCreate-linux 462 ms 412 ms 1.12
lotsOfClasses-sourceToMdapi-linux 3458 ms 3457 ms 1.00
lotsOfClasses-sourceToZip-linux 2832 ms 2731 ms 1.04
lotsOfClasses-mdapiToSource-linux 3297 ms 3274 ms 1.01
lotsOfClassesOneDir-componentSetCreate-linux 731 ms 719 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-linux 6068 ms 6045 ms 1.00
lotsOfClassesOneDir-sourceToZip-linux 4830 ms 4769 ms 1.01
lotsOfClassesOneDir-mdapiToSource-linux 5898 ms 5851 ms 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 8ee12bc Previous: 4b31051 Ratio
eda-componentSetCreate-win32 707 ms 670 ms 1.06
eda-sourceToMdapi-win32 3897 ms 4103 ms 0.95
eda-sourceToZip-win32 3077 ms 3091 ms 1.00
eda-mdapiToSource-win32 6036 ms 5534 ms 1.09
lotsOfClasses-componentSetCreate-win32 1208 ms 1204 ms 1.00
lotsOfClasses-sourceToMdapi-win32 7508 ms 7753 ms 0.97
lotsOfClasses-sourceToZip-win32 4653 ms 4826 ms 0.96
lotsOfClasses-mdapiToSource-win32 7492 ms 7679 ms 0.98
lotsOfClassesOneDir-componentSetCreate-win32 2077 ms 2118 ms 0.98
lotsOfClassesOneDir-sourceToMdapi-win32 13370 ms 13419 ms 1.00
lotsOfClassesOneDir-sourceToZip-win32 8463 ms 8557 ms 0.99
lotsOfClassesOneDir-mdapiToSource-win32 13670 ms 13724 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.