Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Adapt to analyzer, build, linter v3 #948

Merged
merged 14 commits into from
Mar 22, 2018
Merged

Adapt to analyzer, build, linter v3 #948

merged 14 commits into from
Mar 22, 2018

Conversation

valdrinkoshi
Copy link
Member

  • 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, '');
Copy link
Member Author

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

Copy link
Contributor

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);
    }

Copy link
Member Author

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.

@justinfagnani
Copy link
Contributor

@valdrinkoshi can you rebase and try to upgrade to the latest Analyzer 3 preview?

@valdrinkoshi valdrinkoshi changed the title Adapt to analyzer 3 Adapt to analyzer and linter v3 Feb 23, 2018
@valdrinkoshi
Copy link
Member Author

@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 polymer lint I get warnings with the full path, and when invoking polymer lint --fix the warning doesn't get resolved:

$ 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 polymer-linter lately

@stramel
Copy link
Contributor

stramel commented Feb 23, 2018

@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);
Copy link
Contributor

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)

Copy link
Member Author

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!

@valdrinkoshi
Copy link
Member Author

valdrinkoshi commented Feb 24, 2018

@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
Anyways, fixed and tested with:

$ 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).
I think it would be nicer to have relative paths printed on console, no? @rictic WDYT? should we update tests to expect absolute paths here or fix this in the linter?

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);
Copy link
Member Author

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?

Copy link
Contributor

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
Copy link
Contributor

@stramel stramel Mar 6, 2018

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.

rictic
rictic previously requested changes Mar 10, 2018
Copy link
Contributor

@rictic rictic left a 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.

@stramel
Copy link
Contributor

stramel commented Mar 10, 2018

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",
Copy link
Contributor

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"
Copy link
Contributor

@stramel stramel Mar 10, 2018

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?

Copy link
Contributor

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.

Copy link
Contributor

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

@rictic
Copy link
Contributor

rictic commented Mar 12, 2018

@valdrinkoshi valdrinkoshi changed the title Adapt to analyzer and linter v3 Adapt to analyzer, build, linter v3 Mar 12, 2018
@rictic
Copy link
Contributor

rictic commented Mar 22, 2018

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.

valdrinkoshi and others added 9 commits March 22, 2018 13:52
* 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.
src/lint/lint.ts Outdated
for (const [url, newContents] of editedFiles) {
const conversionResult = urlLoader.getFilePath(url);
if (conversionResult.successful === false) {
console.log(
Copy link
Member Author

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?

Copy link
Contributor

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",
Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, done

@rictic rictic dismissed their stale review March 22, 2018 21:51

Dismissing review, updating polymer-build

@valdrinkoshi
Copy link
Member Author

LGTM :shipit:

@rictic rictic merged commit fef450a into master Mar 22, 2018
@rictic rictic deleted the adapt-to-analyzer-3 branch March 22, 2018 22:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants