diff --git a/package.json b/package.json index 5b0164c..8dae704 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,11 @@ ], "description": "With this option you can ignore specific schemes. An item has to match the case-sensitive string of the scheme of the document." }, + "trailing-spaces.pathToIgnore": { + "type": "string", + "default": "", + "description": "With this option you can ignore files whose paths contain a match for the regular expression (case insensitive)." + }, "trailing-spaces.trimOnSave": { "type": "boolean", "default": false, diff --git a/src/trailing-spaces/settings.ts b/src/trailing-spaces/settings.ts index e8aca8b..cc19d74 100644 --- a/src/trailing-spaces/settings.ts +++ b/src/trailing-spaces/settings.ts @@ -12,6 +12,7 @@ export interface TrailingSpacesSettings { deleteModifiedLinesOnly: boolean, languagesToIgnore: { [id: string]: boolean; }, schemesToIgnore: { [id: string]: boolean; }, + pathToIgnore: string, trimOnSave: boolean, showStatusBarMessage: boolean, textEditorDecorationType: vscode.TextEditorDecorationType @@ -30,6 +31,7 @@ export class Settings implements TrailingSpacesSettings { deleteModifiedLinesOnly!: boolean; languagesToIgnore!: { [id: string]: boolean; }; schemesToIgnore!: { [id: string]: boolean; }; + pathToIgnore!: string; trimOnSave!: boolean; showStatusBarMessage!: boolean; textEditorDecorationType!: vscode.TextEditorDecorationType; @@ -56,6 +58,7 @@ export class Settings implements TrailingSpacesSettings { this.deleteModifiedLinesOnly = config.get('deleteModifiedLinesOnly'); this.languagesToIgnore = this.getMapFromStringArray(config.get('syntaxIgnore')); this.schemesToIgnore = this.getMapFromStringArray(config.get('schemeIgnore')); + this.pathToIgnore = config.get('pathToIgnore'); this.trimOnSave = config.get('trimOnSave'); this.showStatusBarMessage = config.get('showStatusBarMessage'); this.textEditorDecorationType = this.getTextEditorDecorationType(config.get('backgroundColor'), config.get('borderColor')); @@ -74,6 +77,7 @@ export class Settings implements TrailingSpacesSettings { config.update('deleteModifiedLinesOnly', undefined, true); config.update('syntaxIgnore', undefined, true); config.update('schemeIgnore', undefined, true); + config.update('pathToIgnore', undefined, true); config.update('trimOnSave', undefined, true); config.update('showStatusBarMessage', undefined, true); config.update('backgroundColor', undefined, true); diff --git a/src/trailing-spaces/trailing-spaces.ts b/src/trailing-spaces/trailing-spaces.ts index ea2c9b1..abb5989 100644 --- a/src/trailing-spaces/trailing-spaces.ts +++ b/src/trailing-spaces/trailing-spaces.ts @@ -147,7 +147,7 @@ export class TrailingSpaces { * @returns {vscode.Range[]} An array of ranges containing the trailing spaces */ private findTrailingSpaces(document: vscode.TextDocument): vscode.Range[] { - if (this.ignoreDocument(document.languageId, document.uri.scheme)) { + if (this.ignoreDocument(document.languageId, document.uri)) { this.logger.info(`File with langauge '${document.languageId}' and scheme '${document.uri.scheme}' ignored - ${document.fileName}`); return []; } else { @@ -180,8 +180,19 @@ export class TrailingSpaces { * @param {string} scheme The scheme of the document to be checked * @returns {boolean} A boolean indicating if the document needs to be ignored */ - private ignoreDocument(language: string, scheme: string): boolean { - return (!isNullOrUndefined(language) && this.settings.languagesToIgnore[language] - || !isNullOrUndefined(scheme) && this.settings.schemesToIgnore[scheme]); + private ignoreDocument(language: string, uri: vscode.Uri): boolean { + if (!isNullOrUndefined(language) && this.settings.languagesToIgnore[language]) + return true; + + if (!isNullOrUndefined(uri.scheme) && this.settings.schemesToIgnore[uri.scheme]) + return true; + + if (!isNullOrUndefined(uri.path) + && !isNullOrUndefined(this.settings.pathToIgnore) + && this.settings.pathToIgnore !== '' + && RegExp(this.settings.pathToIgnore, 'i').test(uri.path)) + return true; + + return false; } }