-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: eslint-plugin, make sure dictionary settings make it to cspell-l…
…ib (#4872)
- Loading branch information
Showing
19 changed files
with
273 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ out | |
|
||
temp | ||
tmp | ||
*.log | ||
|
||
# Dependency directories | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/cspell-eslint-plugin/fixtures/issue-4870/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
jest: true, | ||
node: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@cspell/recommended'], | ||
parserOptions: { | ||
ecmaFeatures: { jsx: true }, | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@cspell'], | ||
root: true, | ||
rules: { | ||
'@cspell/spellchecker': [ | ||
'warn', | ||
{ | ||
debugMode: true, | ||
autoFix: true, | ||
cspell: { | ||
dictionaries: ['business-terminology'], | ||
dictionaryDefinitions: [ | ||
{ | ||
name: 'business-terminology', | ||
path: './dictionaries/business-terminology.txt', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/cspell-eslint-plugin/fixtures/issue-4870/cspell.config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# dictionaries: | ||
# - business-terminology | ||
# dictionaryDefinitions: | ||
# - name: business-terminology | ||
# path: ./dictionaries/business-terminology.txt |
2 changes: 2 additions & 0 deletions
2
packages/cspell-eslint-plugin/fixtures/issue-4870/dictionaries/business-terminology.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bestbusiness | ||
friendz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('hello bestbusiness and friendz'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { format } from 'util'; | ||
|
||
const debugMode = false; | ||
|
||
export interface LoggerOptions { | ||
logFile?: string; | ||
cwd?: string; | ||
/** true - write to file, false - output to console. */ | ||
logToFile?: boolean; | ||
/** enable logging by default? */ | ||
enabled?: boolean; | ||
useAsync?: boolean; | ||
} | ||
|
||
export class Logger { | ||
readonly logFile: string; | ||
readonly cwd: string; | ||
logToFile = true; | ||
enabled = true; | ||
useAsync = false; | ||
|
||
constructor(readonly options: LoggerOptions) { | ||
this.cwd = path.resolve(options.cwd || '.'); | ||
const logFileBasename = options.logFile || '.cspell-eslint-plugin.log'; | ||
this.logFile = path.resolve(this.cwd, logFileBasename); | ||
this.logToFile = options.logToFile ?? true; | ||
this.enabled = options.enabled ?? debugMode; | ||
this.useAsync = options.useAsync ?? false; | ||
} | ||
|
||
private _log(...p: Parameters<typeof console.log>): void { | ||
if (!this.enabled) return; | ||
if (!this.logToFile) return console.log(...p); | ||
const message = new Date().toISOString() + ' ' + prefixLines(format(...p), ' ') + '\n'; | ||
this.useAsync | ||
? fs.appendFile(this.logFile, message, (err) => err && console.error(err)) | ||
: fs.appendFileSync(this.logFile, message); | ||
return; | ||
} | ||
|
||
log = this._log.bind(this); | ||
} | ||
|
||
let logger: Logger | undefined; | ||
|
||
export function getDefaultLogger(): Logger { | ||
if (logger) return logger; | ||
logger = new Logger({}); | ||
return logger; | ||
} | ||
|
||
function prefixLines(text: string, prefix: string, startIndex = 1): string { | ||
return text | ||
.split('\n') | ||
.map((line, index) => (index >= startIndex ? prefix + line : line)) | ||
.map((line) => (line.trim() == '' ? '' : line)) | ||
.join('\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.