Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add fixer for use-pipe-transform-interface #260

Merged

Conversation

rafaelss95
Copy link
Member

No description provided.

if (!importDeclaration?.specifiers.length) {
return fixer.insertTextAfterRange(
[0, 0],
`import { ${PIPE_TRANSFORM} } from '${ANGULAR_CORE_MODULE_PATH}';\n`,
);
}
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 case should not happen as in a pipe file you may already have the import from @angular/core, however I prefer to let it here to avoid something strange.

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Nice work!

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Nice work! This changes the output of the integration tests, so the snapshots will need to be updated.

You can just run the integration tests with -u set for jest and then review the changes before committing

@rafaelss95
Copy link
Member Author

rafaelss95 commented Dec 22, 2020

Hello @JamesHenry, sorry to ask here, but do you still have access to the email address james@nrwl.io? If not, could you give me your new email address? I'm trying to contact you there, thanks.

@JamesHenry
Copy link
Member

@rafaelss95 No problem, please could you use james@henry.sc instead?

@rafaelss95
Copy link
Member Author

You can just run the integration tests with -u set for jest and then review the changes before committing

I ran npm run integration-tests in the root folder and I got the following log error:

0 verbose cli [
0 verbose cli   '/usr/local/Cellar/node/15.3.0/bin/node',
0 verbose cli   '/usr/local/bin/npm',
0 verbose cli   'run',
0 verbose cli   'integration-tests'
0 verbose cli ]
1 info using npm@7.0.14
2 info using node@v15.3.0
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/PATH/angular-eslint/.npmrc Completed in 1ms
9 timing config:load:project Completed in 2ms
10 timing config:load:file:/Users/*/.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 10ms
19 verbose npm-session 426629919b90fffd
20 timing npm:load Completed in 21ms
21 timing command:run-script Completed in 84574ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:376:20)
22 verbose stack     at maybeClose (node:internal/child_process:1055:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
23 verbose cwd /Users/PATH/angular-eslint
24 verbose Darwin 20.2.0
25 verbose argv "/usr/local/Cellar/node/15.3.0/bin/node" "/usr/local/bin/npm" "run" "integration-tests"
26 verbose node v15.3.0
27 verbose npm  v7.0.14
28 error code 1
29 error path /Users/PATH/angular-eslint
30 error command failed
31 error command sh -c lerna run integration-tests
32 verbose exit 1

Could you point out to me what I'm missing?

@rafaelss95 rafaelss95 force-pushed the feat/use-pipe-transform-interface branch 2 times, most recently from 2ba8b6f to 261fcd9 Compare December 22, 2020 19:24
@rafaelss95 rafaelss95 force-pushed the feat/use-pipe-transform-interface branch from 261fcd9 to 519e1ef Compare December 22, 2020 19:30
@rafaelss95
Copy link
Member Author

Sorry for the amended commits, I messed up with the rebase.

@JamesHenry
Copy link
Member

Hmm I have never used npm 7, possibly that?

Can you try using yarn as that is what the workspace uses in CI

You did a full install and build of the monorepo before running right?

@@ -1,45 +1,106 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { RuleFixer } from '@typescript-eslint/experimental-utils/dist/ts-eslint';
Copy link
Member Author

Choose a reason for hiding this comment

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

@JamesHenry Could we have RuleFixer exported directly from the main entry point? This deep import just doesn't feels good for me.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, very true, please could you open an issue on typescript-eslint, and add a TODO comment referencing it so we don't forget in future?

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 created the issue typescript-eslint/typescript-eslint#2931 and put a comment here, take a look please.

Copy link
Member

Choose a reason for hiding this comment

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

I've seen Brad's response, shows how rusty I am :) Please can we update this accordingly

@rafaelss95
Copy link
Member Author

You did a full install and build of the monorepo before running right?

That was it 💯! After ran this, I got 36 files changes. Should I commit it all here?

Captura de Tela 2020-12-22 às 16 51 33

@JamesHenry
Copy link
Member

@rafaelss95 Ah no, just the snapshot updates - the other parts of the diff are just the results of the integration tests doing their thing and should not be committed

Linting \\"robot-websites\\"...
All files pass linting.
"
Linting \\"v1014-multi-project-manual-config\\"..."
Copy link
Member

Choose a reason for hiding this comment

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

This snapshot is clearly broken, you can debug by cd'ing into the relevant workspace in the integration-tests package fixtures and running normal ng lint commands

Copy link
Member Author

@rafaelss95 rafaelss95 Dec 23, 2020

Choose a reason for hiding this comment

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

I did and I discovered that the problem is that the ng lint is not running for this folder (v1014-multi-project-manual-config). When I try to run it, I get the following error:

[error] Error: Failed to load plugin '@angular-eslint' declared in '.eslintrc.json#overrides[0]': Cannot find module '/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@angular-eslint/eslint-plugin/dist/index.js'. Please verify that the package.json has a valid "main" entry
Require stack:
- /PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/__placeholder__.js
Referenced from: /PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/.eslintrc.json
    at tryPackage (node:internal/modules/cjs/loader:338:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:551:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:905:27)
    at Function.resolve (node:internal/modules/cjs/helpers:98:19)
    at Object.resolve (/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js:28:50)
    at ConfigArrayFactory._loadPlugin (/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@eslint/eslintrc/lib/config-array-factory.js:1011:39)
    at ConfigArrayFactory._loadExtendedPluginConfig (/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@eslint/eslintrc/lib/config-array-factory.js:831:29)
    at ConfigArrayFactory._loadExtends (/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@eslint/eslintrc/lib/config-array-factory.js:778:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/PATH/angular-eslint/packages/integration-tests/fixtures/v1014-multi-project-manual-config/node_modules/@eslint/eslintrc/lib/config-array-factory.js:719:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

I also noticed that this happens only for this fixture, the others ran normally.

Copy link
Member Author

Choose a reason for hiding this comment

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

@JamesHenry I would appreciate your help on this to move forward with this PR, thanks.

@@ -90,15 +90,15 @@ Object {
"@angular-eslint/component-selector": Array [
"error",
Object {
"prefix": "customprefix",
"prefix": "app",
Copy link
Member

Choose a reason for hiding this comment

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

These prefixes should not have been changed

Copy link
Member Author

Choose a reason for hiding this comment

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

Idk why it has changed, but after revert everything and do a fresh build/run, it didn't change anymore.

@@ -149,15 +149,15 @@ Object {
"@angular-eslint/component-selector": Array [
"error",
Object {
"prefix": "customprefix",
"prefix": "app",
Copy link
Member

Choose a reason for hiding this comment

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

These prefixes should not have been changed

6:35 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box
14:48 error Invalid binding syntax. Use [(expr)] instead @angular-eslint/template/banana-in-box
4:13 error Strings must use singlequote @typescript-eslint/quotes
9:14 error Pipes should implement PipeTransform interface @angular-eslint/use-pipe-transform-interface
Copy link
Member

@JamesHenry JamesHenry Jan 11, 2021

Choose a reason for hiding this comment

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

Hmm, please make sure you actually verify all these changes, it is a red flag that adding a fixer would cause so many changes to the integration-tests and I think most of them are regressions.

The source of this file I have commented on (multiple-inline-templates.page.ts) is:

import { Component } from '@angular/core';

@Component({
  selector: "app-one-inline-template",
  template: `
    <input type="text" name="foo" ([ngModel])="foo">
  `,
})
export class OneInlineTemplateComponent {}

@Component({
  selector: "app-two-inline-template",
  template: `
    <div [oneWay]="oneWay" (emitter)="emitter" ([twoWay])="twoWay"></div>
  `,
})
export class TwoInlineTemplateComponent {}

The use-pipe-transform-interface rule should not be erroring for that source, right?

I believe this is the case for a number of these changes

Copy link
Member Author

Choose a reason for hiding this comment

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

Ups, it should be fine now.

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants