-
Notifications
You must be signed in to change notification settings - Fork 128
Conversation
valdrinkoshi
commented
Jan 11, 2018
- CHANGELOG.md has been updated
src/lint/lint.ts
Outdated
@@ -320,8 +320,9 @@ async function fix( | |||
await applyEdits(edits, makeParseLoader(analyzer, analysis)); | |||
|
|||
for (const [newPath, newContents] of editedFiles) { | |||
const filePath = newPath.replace('file://', '').replace(config.root, ''); |
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 ugly, I'm probably missing something, but makes the --fix work
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.
We need a common utility for this, but something like:
const url = new URL(newPath);
let documentPath = decodeURIComponent(documentURL.pathname);
if (isWindows() && documentPath.startsWith('/')) {
documentPath = documentPath.substring(1);
}
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 moved this url resolution in util
, method resolvePath
. I'm using https://www.npmjs.com/package/url-js for getting the URL
object, as it's a minimal package with no deps.
@valdrinkoshi can you rebase and try to upgrade to the latest Analyzer 3 preview? |
cf93757
to
12f8bf3
Compare
@justinfagnani I've rebased and updated deps to latest analyzer and linter (forgot the linter previously!) I'm still seeing some issues with path resolution: when invoking $ echo "<dom-module name='foo-elem'></dom-module>" > test.html
$ polymer lint test.html -r polymer-2-hybrid
<dom-module name='foo-elem'></dom-module>
~~~~
file:///Users/valdrin/dev/polymer-cli/test.html(1,13) warning [dom-module-invalid-attrs] - Use the "id" attribute rather than "name" to associate the tagName of an element with its dom-module.
Found 1 warning.
$ polymer lint test.html -r polymer-2-hybrid --fix
No fixes to apply. @rictic any ideas on this one? I haven't been following the progresses on |
@valdrinkoshi That fix wasn't part of the lastest release. As of the latest release that should just warn and not be fixable. The next release will have a fix for that warning. |
src/lint/lint.ts
Outdated
@@ -320,8 +320,9 @@ async function fix( | |||
await applyEdits(edits, makeParseLoader(analyzer, analysis)); | |||
|
|||
for (const [newPath, newContents] of editedFiles) { | |||
const documentPath = resolvePath(newPath); |
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 forgot! We added a method on FsUrlLoader to deal with this: FsUrlLoader#getFilePath()
That might mean that we'd have to pass down an FsUrlLoader into this function (I think this collection of functions has enough shared state that it should be a class, but that's a different issue)
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.
oh nice! that makes the whole thing much simpler, we don't need to pass the config around but rather the urlLoader 👌 Fixed!
@stramel good catch, I spent some time on that one w/o realizing i took a test from master instead of v3.0.0-pre.2 :x $ echo "<dom-module id='foo-elem'><style></style><template></template></dom-module>" > test.html
$ polymer lint test.html -r polymer-2
<dom-module id='foo-elem'><style></style><template></template></dom-module>
~~~~~~~
file:///Users/valdrin/dev/polymer-cli/test.html(1,27) warning [style-into-template] - Style tags should not be directchildren of <dom-module>, they should be moved into the <template>
Found 1 warning. 1 can be automatically fixed with --fix. And $ polymer lint test.html -r polymer-2 --fix
Made 2 changes to file:///Users/valdrin/dev/polymer-cli/test.html
Fixed 1 warning. The PR fails because many tests still expect relative paths printed (instead of absolute ones). |
src/lint/lint.ts
Outdated
@@ -320,8 +320,12 @@ async function fix( | |||
await applyEdits(edits, makeParseLoader(analyzer, analysis)); | |||
|
|||
for (const [newPath, newContents] of editedFiles) { | |||
await fs.writeFile( | |||
path.join(config.root, newPath), newContents, {encoding: 'utf8'}); | |||
const documentPath = urlLoader.getFilePath(newPath); |
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.
newPath
is already an absolute path, and urlLoader.getFilePath
returns the same absolute path...I'm a bit confused now: either we use urlLoader to get the relative path here, or we don't use it at all and always print absolute paths. What should be done here?
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.
Hm. newPath should be a URL, documentPath should be a FS path. Is that not what you're seeing?
src/lint/lint.ts
Outdated
@@ -52,18 +51,19 @@ export async function lint(options: Options, config: ProjectConfig) { | |||
minimumSeverity: Severity.WARNING |
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.
@valdrinkoshi Do you mind linking up the new filesToIgnore
option for the WarningFilter
?
/cc @rictic This should cover the last bit of hook-up for ignoring files in linter I believe.
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.
Lint looks good to me now. Just need to get build integration tests passing. Valdrin mentioned he's taking that on.
Can't wait for this so I can test upgrading my element's using all the new rules and fixes in linter! 🎉 |
@@ -15,7 +15,8 @@ | |||
"test": "gulp test lint", | |||
"test:smoke": "gulp test", | |||
"test:integration": "gulp test:integration", | |||
"format": "find src gulpfile.js \\( -iname '*.ts' -o -iname '*.js' \\) -not -path '*fixtures*' | xargs clang-format --style=file -i" | |||
"format": "find src gulpfile.js \\( -iname '*.ts' -o -iname '*.js' \\) -not -path '*fixtures*' | xargs clang-format --style=file -i", |
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 clean this command up a bit by doing,
"format": "find src gulpfile.js -iname '*.[jt]s' -not -path '*fixtures*' | xargs clang-format --style=file -i"
@@ -15,7 +15,8 @@ | |||
"test": "gulp test lint", | |||
"test:smoke": "gulp test", | |||
"test:integration": "gulp test:integration", | |||
"format": "find src gulpfile.js \\( -iname '*.ts' -o -iname '*.js' \\) -not -path '*fixtures*' | xargs clang-format --style=file -i" | |||
"format": "find src gulpfile.js \\( -iname '*.ts' -o -iname '*.js' \\) -not -path '*fixtures*' | xargs clang-format --style=file -i", | |||
"test:watch": "tsc-then -- mocha -c --ui tdd lib/test/integration/*_test.js lib/test/unit/*_test.js lib/test/unit/*/*_test.js" |
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 could shorten this line by using a more complex glob selector if you want,
"test:watch": "tsc-then -- mocha -c --ui tdd 'lib/test/@\\(integration\\|unit\\)/{,!\\(fixtures\\)/**/}/*_test.js'"
Or maybe just tsc-then -- gulp test test:integration
since we already have a configured gulpfile?
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.
The gulp command does too much, it compiles which we're using tsc-then to do quickly and incrementally.
Gulp also doesn't seem to do deduplication, so since both test
and test:integration
both depend on build
it will end up compiling twice.
I often feel like I'm holding gulp wrong though, there's got to be a way to use it so that it doesn't do this… I would think.
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 definitely thought gulp test test:integration
would only run build once, maybe I'm wrong
Linking in locally, it looks like Polymer/polymer-build#314 is all that's needed for the build integration tests to pass. Once Polymer/polymer-build#326 is merged and 3.0.0-pre.1 of build is released this may be ready to merge. |
* If we can't get a file path for a document we need to change, fail and don't write any changes. * Improve the clarity of lint output. Specifically, counting the number of warnings fixed but not mentioning how many changes were made to each individual file, as the disparity is confusing. * Initialize PackageUrlResolver both package dir and component dir.
Also disable the test of custom component directory with build, as custom component directories seem like they only make sense with reusable elements, not applications, and applications are the only packages we expect to be built. Yell at me if this is a wrong assumption.
7432690
to
e1653df
Compare
src/lint/lint.ts
Outdated
for (const [url, newContents] of editedFiles) { | ||
const conversionResult = urlLoader.getFilePath(url); | ||
if (conversionResult.successful === false) { | ||
console.log( |
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.
should we use logger
here and below?
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.
+1 to this fatal error. The rest of the output shouldn't go through the logger I don't think, it should be logged directly to stdout as it's the primary purpose of running the command to log this stuff to stdout.
package.json
Outdated
"polymer-analyzer": "^3.0.0-pre.14", | ||
"polymer-build": "^3.0.0-pre.1", | ||
"polymer-linter": "^3.0.0-pre.3", | ||
"polymer-project-config": "^3.9.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.
probably a merge issue, should keep 3.10.0 here
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.
+1, done
LGTM |