-
Notifications
You must be signed in to change notification settings - Fork 885
Conversation
Thanks for your interest in palantir/tslint, @jhanschoo! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM
I left some suggestions.
src/configuration.ts
Outdated
// As per eslint convention, yaml config is used if present | ||
// over json config | ||
export const JSON_CONFIG_FILENAME = "tslint.json"; | ||
export const CONFIG_FILENAMES = ["tslint.yaml", "tslint.yml", JSON_CONFIG_FILENAME]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider moving the json file to the first position to avoid unnecessary file lookups
I don't think we need to adopt the behavior of ESLint
src/configuration.ts
Outdated
// TODO: remove in v6.0.0 | ||
// Try reading in the entire directory and looking for a file with different casing. | ||
const filenameLower = filename.toLowerCase(); | ||
const result = fs.readdirSync(cwd).find((entry) => entry.toLowerCase() === filenameLower); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reads the directory 3 times, each time only trying to match one file name.
instead it should read the directory once and compare to all possible file names
src/configuration.ts
Outdated
const fileContent = stripComments(fs.readFileSync(resolvedConfigFilePath) | ||
.toString() | ||
.replace(/^\uFEFF/, "")); | ||
if (resolvedConfigFileExt.match(/\.(json|ya?ml)/) !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer /^\.(json|ya?ml)$/.test(resolvedConfigFileExt)
src/configuration.ts
Outdated
rawConfigFile = JSON.parse(fileContent) as RawConfigFile; | ||
if (resolvedConfigFileExt === ".json") { | ||
rawConfigFile = JSON.parse(stripComments(fileContent)) as RawConfigFile; | ||
} else if (resolvedConfigFileExt.match(/ya?ml/) !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this condition will always be true. you can remove the condition
src/configuration.ts
Outdated
}) as RawConfigFile; | ||
} else { | ||
// throw error for static analysis purpose; should not happen | ||
throw new Error("File format not supported yet."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is dead code
package.json
Outdated
@@ -39,10 +39,11 @@ | |||
"dependencies": { | |||
"babel-code-frame": "^6.22.0", | |||
"builtin-modules": "^1.1.1", | |||
"chalk": "^2.1.0", | |||
"chalk": "~2.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into that and open a separate PR. The change shouldn't be necesary if you use yarn
instead of npm
src/configuration.ts
Outdated
showWarningOnce(`Using mixed case tslint.json is deprecated. Found: ${path.join(cwd, result)}`); | ||
// TODO: remove in v6.0.0 | ||
// Try reading in the entire directory and looking for a file with different casing. | ||
const filenameLower = filename.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can probably remove this line while you are here. we already know filename is lowercase
Personally I'd prefer @adidahiya want to share your opinion on this? |
Ok thanks! I'll look into incorporating them in the weekend. |
src/configuration.ts
Outdated
for (const filename of filenames) { | ||
const index = dirFiles.indexOf(filename); | ||
if (index > -1) { | ||
return dirFiles[index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just return filename;
src/configuration.ts
Outdated
.toString() | ||
.replace(/^\uFEFF/, "")); | ||
if (/\.(json|ya?ml)/.test(resolvedConfigFileExt)) { | ||
const fileContent = fs.readFileSync(resolvedConfigFilePath).toString().replace(/^\uFEFF/, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you are already touching this code: if you pass "utf8"
as second argument to fs.readFileSync
, you can simply remove the .toString()
call
test/executable/executableTests.ts
Outdated
assert.isNotNull(err, "process should exit with error"); | ||
assert.strictEqual(err.code, 1, "error code should be 1"); | ||
|
||
assert.include(stderr, "Failed to load", "stderr should contain notification about failing to load json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/json/config/
package.json
Outdated
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=4.8.0" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert the style-only changes in this file
src/configuration.ts
Outdated
if (fs.existsSync(path.join(cwd, filename))) { | ||
return filename; | ||
const dirFiles = fs.readdirSync(cwd); | ||
for (const filename of filenames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be unexpected as it prefers tslint.yaml
over Tslint.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall the approach here seems reasonable and is a minimal change 👍 looks like js-yaml is a relatively light dependency, so i'm cool with taking it now
docs/usage/configuration/index.md
Outdated
@@ -4,12 +4,12 @@ title: Configuring TSLint | |||
permalink: /usage/configuration/ | |||
--- | |||
|
|||
### tslint.json | |||
### The `tslint` File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just name this "TSLint Configuration"
src/configuration.ts
Outdated
rawConfigFile = JSON.parse(fileContent) as RawConfigFile; | ||
if (resolvedConfigFileExt === ".json") { | ||
rawConfigFile = JSON.parse(stripComments(fileContent)) as RawConfigFile; | ||
} else { // /\.ya?ml/.test(resolvedConfigFileExt) === true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this comment doing here? if it's stray code, please delete. if it's explanatory, write some additional words at the beginning (don't start with "/") and put it on its own line
Alright give me a few mins. Should I squash my commits? |
@jhanschoo no need to sqash, we do it anyway while merging |
Ok thanks! |
Thanks @jhanschoo |
Thanks! |
@@ -63,7 +64,10 @@ export interface IConfigurationLoadResult { | |||
results?: IConfigurationFile; | |||
} | |||
|
|||
export const CONFIG_FILENAME = "tslint.json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could actually break some users of our API:
import * as Lint from "tslint";
Lint.Configuration.CONFIG_FILENAME; // no longer valid
I doubt this is used in real world code, so I don't know if this is worth fixing.
Restores the removed export `CONFIG_FILENAME` to avoid breaking API users. Ref: #3433 (comment) [no-log]
Restores the removed export `CONFIG_FILENAME` to avoid breaking API users. Ref: palantir#3433 (comment) [no-log]
PR checklist
Overview of change:
Implement support for yaml. The "js-yaml" library is already being used in documentation, so it's a simple matter of moving a devDependency to a dependency. I know there's talk about using cosmicConfig, but that would require rewriting a number of tests, and this was way simpler haha
Is there anything you'd like reviewers to focus on?
Let me know what other tests I should write.
CHANGELOG.md entry:
[api] Support for YAML config files.