diff --git a/src/index.test.ts b/src/index.test.ts index 1457dda..18ab1d6 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -46,7 +46,7 @@ describe('getTerms', () => { expect(result).not.toContain('coffee'); expect(result).toContain('mocha'); expect( - result.some((term) => Array.isArray(term) && term[1] === 'Node.js') + result.some((term) => Array.isArray(term) && term[1] === 'Node.js'), ).toBe(true); }); @@ -54,7 +54,7 @@ describe('getTerms', () => { const result = getTerms(true, [], ['Node[ .]?js']); expect(result).toBeTruthy(); expect( - result.some((term) => Array.isArray(term) && term[1] === 'Node.js') + result.some((term) => Array.isArray(term) && term[1] === 'Node.js'), ).toBe(false); }); }); @@ -71,21 +71,21 @@ describe('getMultipleWordRegExp', () => { test('should match a pattern as a full word', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'My JavaScript is good' + 'My JavaScript is good', ); expect(result?.[0]).toBe('JavaScript'); }); test('should not match a pattern in the middle of a word', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'Foo superwebpacky bar' + 'Foo superwebpacky bar', ); expect(result).toBeFalsy(); }); test('should not match a pattern at the beginning of a string', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'webpack bar' + 'webpack bar', ); expect(result).toBeTruthy(); expect(result?.[0]).toBe('webpack'); @@ -93,7 +93,7 @@ describe('getMultipleWordRegExp', () => { test('should not match a pattern at the end of a string', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'foo webpack' + 'foo webpack', ); expect(result).toBeTruthy(); expect(result?.[0]).toBe('webpack'); @@ -101,28 +101,28 @@ describe('getMultipleWordRegExp', () => { test('should not match a pattern at the beginning of a word with a hyphen', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'Foo webpack-ish bar' + 'Foo webpack-ish bar', ); expect(result).toBeFalsy(); }); test('should not match a pattern in at the end of a word with a hyphen', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'Foo uber-webpack bar' + 'Foo uber-webpack bar', ); expect(result).toBeFalsy(); }); test('should not match a pattern in at the middle of a word with hyphens', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'Foo uber-webpack-ish bar' + 'Foo uber-webpack-ish bar', ); expect(result).toBeFalsy(); }); test('should match a pattern at the end of a sentence', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'My javascript.' + 'My javascript.', ); expect(result).toBeTruthy(); expect(result?.[0]).toBe('javascript'); @@ -130,7 +130,7 @@ describe('getMultipleWordRegExp', () => { test('should match a pattern at the end of a sentence in the middle of a string', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'My javascript. My webpack.' + 'My javascript. My webpack.', ); expect(result).toBeTruthy(); expect(result?.[0]).toBe('javascript'); @@ -151,21 +151,21 @@ describe('getMultipleWordRegExp', () => { ['Bad Javascript?'], ])('should match a pattern regardless of punctuation: %s', (string) => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - string + string, ); expect(result).toBeTruthy(); }); test('should not match a pattern in as a part of a file name', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'javascript.md' + 'javascript.md', ); expect(result).toBeFalsy(); }); test('should match a pattern regardless of its case', () => { const result = new RegExp(getMultipleWordRegExp(variants), 'igm').exec( - 'Javascript is good' + 'Javascript is good', ); expect(result).toBeTruthy(); expect(result?.[0]).toBe('Javascript'); @@ -219,7 +219,7 @@ describe('getAdvancedRegExp', () => { test('should return regexp as is if it has look behinds', () => { const regexp = new RegExp( getAdvancedRegExp(String.raw`(?<=(?:\w+[^.?!])? )base64\b`), - 'igm' + 'igm', ); expect(regexp.test('use Base64')).toBeTruthy(); }); @@ -227,7 +227,7 @@ describe('getAdvancedRegExp', () => { test('should return regexp as is if it has positive look ahead', () => { const regexp = new RegExp( getAdvancedRegExp(String.raw`base64(?= \w)`), - 'igm' + 'igm', ); expect(regexp.test('Base64 foo')).toBeTruthy(); }); @@ -235,7 +235,7 @@ describe('getAdvancedRegExp', () => { test('should return regexp as is if it has negative look ahead', () => { const regexp = new RegExp( getAdvancedRegExp(String.raw`base64(?! \w)`), - 'igm' + 'igm', ); expect(regexp.test('Base64')).toBeTruthy(); expect(regexp.test('Base64 foo')).toBeFalsy(); @@ -244,7 +244,7 @@ describe('getAdvancedRegExp', () => { test('should not match words inside filenames', () => { const regexp = new RegExp( getAdvancedRegExp(String.raw`(? { const result = getReplacement( 'JavaScript', ['npm', 'JavaScript', 'webpack'], - 'Javascript' + 'Javascript', ); expect(result).toEqual('JavaScript'); }); @@ -420,5 +420,5 @@ tester.run( ], }, ], - } + }, ); diff --git a/src/index.ts b/src/index.ts index 7395721..330ec79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ const punctuation = String.raw`[\.,;:!?'"’”)]`; function reporter( context: TextlintRuleContext, - userOptions: Partial = {} + userOptions: Partial = {}, ) { const options = { ...DEFAULT_OPTIONS, ...userOptions }; const terms = getTerms(options.defaultTerms, options.terms, options.exclude); @@ -48,7 +48,7 @@ function reporter( // Create a separate regexp of each array rule ([pattern, replacement]) const advancedRules: Tuple[] = terms.filter( - (rule) => typeof rule !== 'string' + (rule) => typeof rule !== 'string', ); const rules = [...exactWordRules, ...advancedRules]; @@ -62,7 +62,7 @@ function reporter( helper.isChildNode( // @ts-expect-error: Who the fuck knows what you want here ;-/ node, - options.skip.map((rule) => Syntax[rule]) + options.skip.map((rule) => Syntax[rule]), ) ) { return resolve(); @@ -73,7 +73,7 @@ function reporter( for (const [pattern, replacements] of rules) { const regExp = new RegExp( typeof pattern === 'string' ? getAdvancedRegExp(pattern) : pattern, - 'igm' + 'igm', ); let match; @@ -102,7 +102,7 @@ function reporter( const fix = fixer.replaceTextRange( [index, index + matched.length], - replacement + replacement, ); const message = `Incorrect term: “${matched.trim()}”, use “${replacement.trim()}” instead`; report(node, new RuleError(message, { index, fix })); @@ -118,7 +118,7 @@ function reporter( export function getTerms( defaultTerms: boolean, terms: string | Term[], - exclude: string[] + exclude: string[], ) { const defaults = defaultTerms ? loadJson('../terms.jsonc') : []; const extras = typeof terms === 'string' ? loadJson(terms) : terms; @@ -188,7 +188,7 @@ export function getAdvancedRegExp(pattern: string) { export function getReplacement( pattern: string, replacements: string | string[], - matched: string + matched: string, ) { if (Array.isArray(replacements)) { return findWord(replacements, matched); diff --git a/terms.jsonc b/terms.jsonc index 48f9aba..0ec03d5 100644 --- a/terms.jsonc +++ b/terms.jsonc @@ -277,8 +277,8 @@ // Cases ["kebab[_ ]?case", "kebab-case"], - ["camel[_- ]?case", "camelCase"], - ["pascal[_- ]?case", "PascalCase"], + ["camel[-_ ]?case", "camelCase"], + ["pascal[-_ ]?case", "PascalCase"], ["snake[- ]?case", "snake_case"], ["screaming[- ]?snake[- ]?case", "SCREAMING_SNAKE_CASE"],