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

lint: use gitignore, enforce prettier rules #5307

Merged
merged 6 commits into from
Jul 12, 2024
Merged

Conversation

justinmk3
Copy link
Contributor

Problem

  • .eslintignore is mostly redundant with .gitignore and is missing something specified by .gitignore.
  • some prettier rules are not enforced by our eslint rules. For example, if a developer doesn't have prettier configured, they may commit files without EOL and this isn't caught by our lint CI.

Solution

  • use eslint --ignore-path .gitignore and remove .eslintignore
  • install eslint-plugin-prettier which automatically enforces prettier rules as eslint rules.

Note: the formatting changes are from arrowParens=always. See commit for details.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@justinmk3 justinmk3 requested review from a team as code owners July 12, 2024 11:39
@@ -16,7 +16,7 @@
"singleQuote": true,
"semi": false,
"bracketSpacing": true,
"arrowParens": "avoid",
"arrowParens": "always",
Copy link
Contributor Author

@justinmk3 justinmk3 Jul 12, 2024

Choose a reason for hiding this comment

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

Partial solution work for #3662

Copy link
Contributor

@hayemaxi hayemaxi Jul 12, 2024

Choose a reason for hiding this comment

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

How does this partially solve the issue? Seems like arrowParens only adds parenthesis around the arguments, but the issue is relating to how arrow funcs structure their returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅 yeah, it doesn't directly solve #3662 . I should have said "this is something I discovered while working on #3662 , and since arrowParens:always is now the default for what appears to be a solid rationale, I enabled it".

@@ -32,10 +32,8 @@
"package": "npm run package -w packages/toolkit -w packages/amazonq",
"newChange": "echo 'Must specify subproject/workspace with -w packages/<subproject>' && false",
"createRelease": "echo 'Must specify subproject/workspace with -w packages/<subproject>' && false",
"format": "prettier --check plugins && npm run format -w packages/ --if-present",
"formatfix": "prettier --write plugins && npm run formatfix -w packages/ --if-present",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all format and formatfix tasks. They're redundant now that eslint enforces prettier rules.

"lint": "npm run lint -w packages/ --if-present && npm run format",
"lintfix": "eslint -c .eslintrc.js --fix --ext .ts packages plugins && npm run formatfix",
"lint": "npm run lint -w packages/ --if-present",
"lintfix": "eslint -c .eslintrc.js --ignore-path .gitignore --ignore-pattern '**/*.json' --ignore-pattern '**/*.gen.ts' --ignore-pattern '**/types/*.d.ts' --ignore-pattern '**/src/testFixtures/**' --ignore-pattern '**/resources/js/graphStateMachine.js' --fix --ext .ts packages plugins",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Future: need to extract the eslint invocation to something like scripts/lint.ts.

],
{
throws: false,
}
)
assert.strictEqual(result.status, 0, result.stdout.toString())
assert.strictEqual(result.status, 0, result.output.toString())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stderr wasn't shown

Comment on lines +34 to +38
'../amazonq',
'../core',
'../toolkit',
// TODO: fix lint issues in scripts/
// '../../scripts',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

run eslint on all packages.

Future: testLint/ should live outside of core/

Comment on lines +18 to +23
// Note: eslint currently does not support multiple --ignore-path args.
// Use --ignore-pattern as a workaround.
'--ignore-path',
'../../.eslintignore',
'../../.gitignore',
'--ignore-pattern',
'**/*.json',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re-use gitignore instead of eslintignore

@justinmk3 justinmk3 changed the title lint: lint: use gitignore, enforce prettier rules Jul 12, 2024
@justinmk3
Copy link
Contributor Author

/runintegrationtests

@justinmk3 justinmk3 force-pushed the lint branch 2 times, most recently from d9848fd to 6e49f31 Compare July 12, 2024 13:52
Problem:
javascript arrow functions allow braces `{ ... }` to surround an
expression without a `return`, which leads to bugs such as
aws#3659
aws#3662

Example:

    return supplementalContexts.filter(item => { item.content.trim().length !== 0 })

should be:

    return supplementalContexts.filter(item => item.content.trim().length !== 0)

Solution:
- Set prettier `arrowParens=always`. This is the default, explained
  here: https://prettier.io/docs/en/options.html#arrow-function-parentheses
  > At first glance, avoiding parentheses may look like a better choice
  because of less visual noise. However, when Prettier removes
  parentheses, it becomes harder to add type annotations, extra
  arguments or default values as well as making other changes.
  Consistent use of parentheses provides a better developer experience
  when editing real codebases, which justifies the default value for the
  option.
- Note: this is equivalent to the eslint `@stylistic/no-confusing-arrow` rule.
  - https://eslint.style/packages/default#stylistic-eslint-plugin
  - https://eslint.style/rules/default/no-confusing-arrow
This task was added as workaround. It's not need now because we have
"eslint-plugin-prettier" installed which tells eslint to include rules
decided by our prettier config.
Since our eslint rules now are informed by our prettier config
(performed by the "eslint-plugin-prettier" package), `prettier --write`
is unnecessary because it's implictly done by `eslint --fix`.

https://github.com/prettier/eslint-plugin-prettier
TODO: extract the eslint invocation to scripts/lint.ts so that it's not
duplicated in the "lintfix" task.
@justinmk3 justinmk3 merged commit 56b1c4b into aws:master Jul 12, 2024
15 of 17 checks passed
@justinmk3 justinmk3 deleted the lint branch July 12, 2024 16:13
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.

2 participants