Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading