From 3607fd87c743ffec8da1e2639d7693293f67311d Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Tue, 24 Dec 2019 10:14:15 +0100 Subject: [PATCH 1/2] [cspell] Enable Email exclusion by default --- packages/cspell-lib/samples/.cspell.json | 11 ++- packages/cspell-lib/samples/sample.py | 98 ------------------- packages/cspell-lib/samples/src/sample.py | 10 +- .../src/Settings/DefaultSettings.ts | 1 + packages/cspell-lib/src/test/python.spec.ts | 6 +- 5 files changed, 23 insertions(+), 103 deletions(-) delete mode 100644 packages/cspell-lib/samples/sample.py diff --git a/packages/cspell-lib/samples/.cspell.json b/packages/cspell-lib/samples/.cspell.json index 789cfe0b300..adca2b9715a 100644 --- a/packages/cspell-lib/samples/.cspell.json +++ b/packages/cspell-lib/samples/.cspell.json @@ -9,7 +9,8 @@ "words": [ "gensequence", "xregexp", - "sampletrace" + "sampletrace", + "findall" ], "maxNumberOfProblems": 10000, "ignorePaths": [ @@ -61,6 +62,11 @@ "dictionaries": ["cpp"], // Dictionary definitions can also be supplied here. They are only used iff "languageId" and "local" match. "dictionaryDefinitions": [] + }, + { + // Turn off allowCompoundWords for Python + "languageId": "python", + "allowCompoundWords": false } ], @@ -76,7 +82,8 @@ "dictionaryDefinitions": [ { "name": "cpp", - "path": "../dictionaries/companies.txt", + "path": "../dictionaries", + "file": "companies.txt", "description": "C/C++ Keywords and common library functions." } ] diff --git a/packages/cspell-lib/samples/sample.py b/packages/cspell-lib/samples/sample.py deleted file mode 100644 index 99eb3c4498a..00000000000 --- a/packages/cspell-lib/samples/sample.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Roman Numbers""" -import re - -class OutOfRangeError(ValueError): pass -class NotIntegerError(ValueError): pass -class InvalidRomanNumeral(ValueError): pass - -romanNumeralValues = { - 'I': 1, - 'V': 5, - 'X': 10, - 'L': 50, - 'C': 100, - 'D': 500, - 'M': 1000, - 'II': 2, - 'III': 3, - 'IV': 4, - 'IX': 9, - 'XX': 20, - 'XXX': 30, - 'XL': 40, - 'XC': 90, - 'CC': 200, - 'CCC': 300, - 'CD': 400, - 'CM': 900, - 'MM': 2000, - 'MMM': 3000, - 'MMMM': 4000, -} - -ordered = sorted([(a[1], a[0]) for a in romanNumeralValues.items()], reverse=True) - -def to_roman(number): - if not isinstance(number, int): - raise NotIntegerError('Non-integers cannot be converted.') - - if not (0 < number < 5000): - raise OutOfRangeError('Valid numbers are 1 to 4999, got {0}'.format(number)) - - r = '' - for (num, numeral) in ordered: - if num <= number: - number -= num - r += numeral - return r - -# Match against the numerals required for each digit -reMatchRoman = re.compile(r''' - ^ - (M{0,4})? # thousands - (CM|CD|D?C{0,3})? # hundreds - (XC|XL|L?X{0,3})? # tens - (IX|IV|V?I{0,3})? # ones - $ - ''', re.VERBOSE) - -# Split numerals up so we can look them up in romanNumeralValues -reSplitNumerals = re.compile(r"CM|D|CD|XC|L|XL|IX|V|IV|M+|C+|X+|I+") - -def is_valid(roman): - return reMatchRoman.match(roman) != None - -def to_number(roman): - if not isinstance(roman, str): - raise InvalidRomanNumeral('Only valid roman numerals are allowed.') - - roman = roman.upper().strip() - if not roman: - raise InvalidRomanNumeral('Only valid roman numerals are allowed.') - - match = reMatchRoman.match(roman.upper()) - if match == None: - raise InvalidRomanNumeral('Only valid roman numerals are allowed.') - value = 0 - for digit in match.groups(): - for numeral in reSplitNumerals.findall(digit): - value += romanNumeralValues[numeral] - return value - -binary = b'binary' -unicode = u'unicode' - -if __name__ == '__main__': - print(to_roman(1984)) - print(is_valid(to_roman(1999))) - print(is_valid('hello')) - print(to_roman(1492)) - print(to_number(to_roman(1492))) - print(to_roman(1888)) - print(to_number(to_roman(1888))) - for n in range(1, 4999): - # print(to_roman(n)) - is_valid(to_roman(n)) - if n != to_number(to_roman(n)): - raise ValueError('Failed on %d' % n) - print('Done.') diff --git a/packages/cspell-lib/samples/src/sample.py b/packages/cspell-lib/samples/src/sample.py index d94c70d4d03..337a8fa8217 100644 --- a/packages/cspell-lib/samples/src/sample.py +++ b/packages/cspell-lib/samples/src/sample.py @@ -1,4 +1,10 @@ -"""Roman Numbers""" +""" +Roman Numbers + +Sample Python file. + +with email address: ExampleCode +""" import re class OutOfRangeError(ValueError): pass @@ -79,6 +85,8 @@ def to_number(roman): value += romanNumeralValues[numeral] return value +binary = b'binary' +unicode = u'unicode' if __name__ == '__main__': print(to_roman(1984)) diff --git a/packages/cspell-lib/src/Settings/DefaultSettings.ts b/packages/cspell-lib/src/Settings/DefaultSettings.ts index 8923d8a371c..307626bd0a3 100644 --- a/packages/cspell-lib/src/Settings/DefaultSettings.ts +++ b/packages/cspell-lib/src/Settings/DefaultSettings.ts @@ -10,6 +10,7 @@ import { mergeSettings } from './index'; const defaultRegExpExcludeList = [ 'SpellCheckerDisable', 'Urls', + 'Email', 'PublicKey', 'RsaCert', 'Base64', diff --git a/packages/cspell-lib/src/test/python.spec.ts b/packages/cspell-lib/src/test/python.spec.ts index 13ce71a1aac..e873b8be90c 100644 --- a/packages/cspell-lib/src/test/python.spec.ts +++ b/packages/cspell-lib/src/test/python.spec.ts @@ -4,7 +4,9 @@ import * as path from 'path'; import * as fsp from 'fs-extra'; -const sampleFilename = path.join(__dirname, '..', '..', 'samples', 'src', 'sample.py'); +const samples = path.join(__dirname, '..', '..', 'samples'); +const sampleFilename = path.join(samples, 'src', 'sample.py'); +const sampleConfig = path.join(samples, '.cspell.json'); const sampleFile = fsp.readFile(sampleFilename, 'UTF-8').then(buffer => buffer.toString()); describe('Validate that Python files are correctly checked.', () => { @@ -14,7 +16,7 @@ describe('Validate that Python files are correctly checked.', () => { expect(text).to.not.be.empty; const ext = path.extname(sampleFilename); const languageIds = cspell.getLanguagesForExt(ext); - const settings = cspell.getDefaultSettings(); + const settings = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.readSettings(sampleConfig)); const fileSettings = cspell.combineTextAndLanguageSettings(settings, text, languageIds); return cspell.validateText(text, fileSettings) .then(results => { From 2b3c8818c6be337c2a077056cd4393994e0607d4 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Tue, 24 Dec 2019 10:22:25 +0100 Subject: [PATCH 2/2] Email issues are now ignored --- packages/cspell/src/application.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cspell/src/application.test.ts b/packages/cspell/src/application.test.ts index dfdac81ce3d..0d46ec667ea 100644 --- a/packages/cspell/src/application.test.ts +++ b/packages/cspell/src/application.test.ts @@ -115,7 +115,7 @@ function sampleTests(): SampleTest[] { { file: 'samples/src/sample.c', issues: [] }, { file: 'samples/src/sample.go', issues: ['garbbage'] }, { file: 'samples/src/sample.py', issues: ['garbbage'] }, - { file: 'samples/src/sample.tex', issues: ['hammersley', 'gmail', 'includegraphics', 'Zotero'] }, + { file: 'samples/src/sample.tex', issues: ['includegraphics', 'Zotero'] }, ]; // cspell:enable }