@fimbul/wotan
Advanced tools
Comparing version 0.18.0-dev.20181231 to 0.18.0-dev.20190103
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.18.0-dev.20181231", | ||
"version": "0.18.0-dev.20190103", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
@@ -66,3 +66,3 @@ "bin": "bin/main.js", | ||
"tslib": "^1.8.1", | ||
"tsutils": "^3.5.0" | ||
"tsutils": "^3.6.0" | ||
}, | ||
@@ -69,0 +69,0 @@ "peerDependencies": { |
@@ -52,3 +52,3 @@ # Wotan | ||
Wotan is configured with a YAML, JSON5 or JSON file named `.wotanrc.yaml`, `.wotanrc.json5` or `.wotanrc.json`. By default the configuration file from the closes parent folder is used to lint each file. | ||
Wotan is configured with a YAML, JSON5 or JSON file named `.wotanrc.yaml`, `.wotanrc.json5` or `.wotanrc.json`. By default the configuration file from the closest parent folder is used to lint each file. | ||
@@ -76,2 +76,4 @@ You can use different configurations for different directories. Consider the following setup: | ||
Note: this describes the default configuration file name and content. Plugin modules are able to override this behavior to read files with different name or content. | ||
### Overrides | ||
@@ -145,2 +147,4 @@ | ||
This is the default behavior which can be overridden by plugin modules. | ||
## CLI Options | ||
@@ -214,2 +218,30 @@ | ||
## Linting with Type Information | ||
When linting a project (`--project` CLI option) rules are able to use type information using TypeScript's API. Some rules report more findings with type information, some other rules require type information for each of their checks. | ||
If a rule cannot work properly without type information, you will see a warning like `Rule 'foo' requires type information.` | ||
### Special Handling of JavaScript Files | ||
TypeScript can analyze and check JavaScript files. However, it only does this if you explicitly ask for it using `"allowJs": true, "checkJs": true` in your `tsconfig.json` or by adding a `// @ts-check` comment on top of your JS files. | ||
A `// @ts-nocheck` comment excludes a file from type checking. | ||
More information is available in the official [TypeScript Handbook: Type Checking JavaScript Files](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html). | ||
Wotan respects these flags, too. That means it will not provide type information to rules executed on unchecked JS files. | ||
This ensures you won't get surprising lint findings caused by funky type inference in those files. | ||
You will still get reports for purely syntactic findings, i.e. rules that don't require type information. | ||
### Excluded Files | ||
If type information is available Wotan excludes all files you haven't written yourself. The following files are always excluded so you cannot explicitly include them: | ||
* any files of dependencies in `node_modules` (unless imported using a relative path, e.g. `./node_modules/foo/index`) | ||
* declaration files from `@types` (or `typeRoots` declared in your `tsconfig.json`) | ||
* declaration files included by TypeScript, e.g. `lib.es5.d.ts` | ||
* declaration files of project references (`references` in `tsconfig.json`) | ||
This is the default behavior which can be overridden by plugin modules. | ||
If you lint individual files without type information using the file's path or a glob pattern, you are responsible for excluding all files you don't want to lint. | ||
## Diagnosing Misbehavior | ||
@@ -216,0 +248,0 @@ |
@@ -67,4 +67,13 @@ "use strict"; | ||
getFindings(sourceFile, config, program, processor) { | ||
let suppressMissingTypeInfoWarning = false; | ||
log('Linting file %s', sourceFile.fileName); | ||
const rules = this.prepareRules(config, sourceFile, program); | ||
if (program !== undefined && /\.jsx?/.test(sourceFile.fileName)) { | ||
const directive = tsutils_1.getCheckJsDirective(sourceFile.text); | ||
if (directive === undefined ? !tsutils_1.isCompilerOptionEnabled(program.getCompilerOptions(), 'checkJs') : !directive.enabled) { | ||
log('Not using type information for this unchecked JS file'); | ||
program = undefined; | ||
suppressMissingTypeInfoWarning = true; | ||
} | ||
} | ||
const rules = this.prepareRules(config, sourceFile, program, suppressMissingTypeInfoWarning); | ||
if (rules.length === 0) { | ||
@@ -77,3 +86,3 @@ log('No active rules'); | ||
} | ||
prepareRules(config, sourceFile, program) { | ||
prepareRules(config, sourceFile, program, noWarn) { | ||
const rules = []; | ||
@@ -89,7 +98,12 @@ for (const [ruleName, { options, severity, rulesDirectories, rule }] of config.rules) { | ||
if (program === undefined && ctor.requiresTypeInformation) { | ||
this.logger.warn(`Rule '${ruleName}' requires type information.`); | ||
if (noWarn) { | ||
log('Rule %s requires type information', ruleName); | ||
} | ||
else { | ||
this.logger.warn(`Rule '${ruleName}' requires type information.`); | ||
} | ||
continue; | ||
} | ||
if (ctor.supports !== undefined && !ctor.supports(sourceFile, { program, options, settings: config.settings })) { | ||
log(`Rule %s does not support this file`, ruleName); | ||
log('Rule %s does not support this file', ruleName); | ||
continue; | ||
@@ -96,0 +110,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303008
3759
251
Updatedtsutils@^3.6.0