Skip to content

Commit

Permalink
fix: file globs listed on the command line override files in the conf…
Browse files Browse the repository at this point in the history
…ig. (#1117)

* fix: file globs listed on the command line override files in the config.

Fixes #1115

* test: Add a unit test for command line file overrides.
  • Loading branch information
Jason3S committed Apr 2, 2021
1 parent 77ae68a commit 25c501d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
10 changes: 10 additions & 0 deletions packages/cspell/samples/latex/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
// Version of the setting file. Always 0.1
"version": "0.2",
// language - current active spelling language
"language": "en",
"files": [
"**/*.tex"
]
}
11 changes: 7 additions & 4 deletions packages/cspell/samples/latex/ebook/ebook.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% eBook
% eBook
% LaTeX Template
% Version 1.0 (29/12/14)
%
Expand All @@ -15,6 +15,9 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% cspell:locale en
% cspell:words Luis Cobo Grimms Gothel

%----------------------------------------------------------------------------------------
% DOCUMENT CONFIGURATIONS AND INFORMATION
%----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -184,7 +187,7 @@ \chapter{Hansel and Gretel}

and went on eating without disturbing themselves. Hansel, who liked the taste of the roof, tore down a great piece of it, and Gretel pushed out the whole of one round window-pane, sat down, and enjoyed herself with it. Suddenly the door opened, and a woman as old as the hills, who supported herself on crutches, came creeping out. Hansel and Gretel were so terribly frightened that they let fall what they had in their hands. The old woman, however, nodded her head, and said: `Oh, you dear children, who has brought you here? do come in, and stay with me. No harm shall happen to you.' She took them both by the hand, and led them into her little house. Then good food was set before them, milk and pancakes, with sugar, apples, and nuts. Afterwards two pretty little beds were covered with clean white linen, and Hansel and Gretel lay down in them, and thought they were in heaven.

The old woman had only pretended to be so kind; she was in reality a wicked witch, who lay in wait for children, and had only built the little house of bread in order to entice them there. When a child fell into her power, she killed it, cooked and ate it, and that was a feast day with her. Witches have red eyes, and cannot see far, but they have a keen scent like the beasts, and are aware when human beings draw near. When Hansel and Gretel came into her neighbourhood, she laughed with
The old woman had only pretended to be so kind; she was in reality a wicked witch, who lay in wait for children, and had only built the little house of bread in order to entice them there. When a child fell into her power, she killed it, cooked and ate it, and that was a feast day with her. Witches have red eyes, and cannot see far, but they have a keen scent like the beasts, and are aware when human beings draw near. When Hansel and Gretel came into her neighborhood, she laughed with
malice, and said mockingly: `I have them, they shall not escape me again!' Early in the morning before the children were awake, she was already up, and when she saw both of them sleeping and looking so pretty, with their plump and rosy cheeks she muttered to herself: `That will be a dainty mouthful!' Then she seized Hansel with her shrivelled hand, carried him into a little stable, and locked him in behind a grated door. Scream as he might, it would not help him. Then she went to
Gretel, shook her till she awoke, and cried: `Get up, lazy thing, fetch some water, and cook something good for your brother, he is in the stable outside, and is to be made fat. When he is fat, I will eat him.' Gretel began to weep bitterly, but it was all in vain, for she was forced to do what the wicked witch commanded.

Expand All @@ -210,7 +213,7 @@ \chapter{Hansel and Gretel}
% CHAPTER THREE
%----------------------------------------------------------------------------------------

\chapter{Rupunzel}
\chapter{Rapunzel}

There were once a man and a woman who had long in vain wished for a child. At length the woman hoped that God was about to grant her desire. These people had a little window at the back of their house from which a splendid garden could be seen, which was full of the most beautiful flowers and herbs. It was, however, surrounded by a high wall, and no one dared to go into it because it belonged to an enchantress, who had great power and was dreaded by all the world. One day the woman was standing by this window and looking down into the garden, when she saw a bed which was planted with the most beautiful rampion (rapunzel), and it looked so fresh and green that she longed for it, she quite pined away, and began to look pale and miserable. Then her husband was alarmed, and asked: `What ails you, dear wife?' `Ah,' she replied, `if I can't eat some of the rampion, which is in the garden behind our house, I shall die.' The man, who loved her, thought: `Sooner than let your wife die, bring her some of the rampion yourself, let it cost what it will.' At twilight, he clambered down over the wall into the garden of the enchantress, hastily clutched a handful of rampion, and took it to his wife. She at once made herself a salad of it, and ate it greedily. It tasted so good to her--so very good, that the next day she longed for it three times as much as before. If he was to have any rest, her husband must once more descend into the garden. In the gloom of evening therefore, he let himself down again; but when he had clambered down the wall he was terribly afraid, for he saw the enchantress standing before him. `How can you dare,' said she with angry look, `descend into my garden and steal my rampion like a thief? You shall suffer for it!' `Ah,' answered he, `let mercy take the place of justice, I only made up my mind to do it out of necessity. My wife saw your rampion from the window, and felt such a longing for it that she would have died if she had not got some to eat.' Then the enchantress allowed her anger to be softened, and said to him: `If the case be as you say, I will allow you to take away with you as much rampion as you will, only I make one condition, you must give me the child which your wife will bring into the world; it shall be well treated, and I will care for it like a mother.' The man in his terror consented to everything, and when the woman was brought to bed, the enchantress appeared at once, gave the child the name of Rapunzel, and took it away with her.

Expand Down Expand Up @@ -247,4 +250,4 @@ \chapter{Rupunzel}

%----------------------------------------------------------------------------------------

\end{document}
\end{document}
3 changes: 3 additions & 0 deletions packages/cspell/samples/latex/latex.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
\documentclass[12pt]{article}
\usepackage{amsmath}

% cspell:words Leslie Lamport

\title{\LaTeX}
\date{}
\begin{document}
Expand Down
56 changes: 56 additions & 0 deletions packages/cspell/src/lint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { runLint } from './lint';
import { CSpellApplicationConfiguration } from './CSpellApplicationConfiguration';
import { Emitters, Issue, ProgressFileComplete } from './emitters';
import * as path from 'path';

const samples = path.resolve(__dirname, '../samples');
const latexSamples = path.resolve(samples, 'latex');

describe('Linter Validation Tests', () => {
test('globs on the command line override globs in the config.', async () => {
const options = { root: latexSamples };
const logger = new Logger();
const rWithoutFiles = await runLint(new CSpellApplicationConfiguration([], options, logger));
expect(rWithoutFiles.files).toBe(4);
const rWithFiles = await runLint(new CSpellApplicationConfiguration(['**/ebook.tex'], options, logger));
expect(rWithFiles.files).toBe(1);
});
});

class Logger implements Emitters {
log: string[] = [];
issueCount = 0;
errorCount = 0;
debugCount = 0;
infoCount = 0;
progressCount = 0;
issues: Issue[] = [];

issue = (issue: Issue) => {
this.issues.push(issue);
this.issueCount += 1;
const { uri, row, col, text } = issue;
this.log.push(`Issue: ${uri}[${row}, ${col}]: Unknown word: ${text}`);
};

error = (message: string, error: Error) => {
this.errorCount += 1;
this.log.push(`Error: ${message} ${error.toString()}`);
return Promise.resolve();
};

info = (message: string) => {
this.infoCount += 1;
this.log.push(`Info: ${message}`);
};

debug = (message: string) => {
this.debugCount += 1;
this.log.push(`Debug: ${message}`);
};

progress = (p: ProgressFileComplete) => {
this.progressCount += 1;
this.log.push(`Progress: ${p.type} ${p.fileNum} ${p.fileCount} ${p.filename}`);
};
}
2 changes: 1 addition & 1 deletion packages/cspell/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function runLint(cfg: CSpellApplicationConfiguration): Promise<RunResult>

const configInfo: ConfigInfo = await readConfig(cfg.configFile, cfg.root);
const cliGlobs: Glob[] = cfg.files;
const allGlobs: Glob[] = cliGlobs.concat(configInfo.config.files || []);
const allGlobs: Glob[] = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
const combinedGlobs = normalizeGlobsToRoot(allGlobs, cfg.root, false);
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!'));
Expand Down

0 comments on commit 25c501d

Please sign in to comment.