-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Add Eslint to sentry-javascript #2786
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e9b7617
feat: Create eslint config
AbhiPrasad 7b25820
Update rules
AbhiPrasad a20b8b5
more changes
AbhiPrasad c73025f
ref: Remove tslint-disable comments
AbhiPrasad 6aa1c09
with eslint danger
AbhiPrasad 77f7a33
clean up danger file
AbhiPrasad a6059f8
see if dangerfile gets it
AbhiPrasad b4513b4
fix it
AbhiPrasad f2d3039
fix parser services
AbhiPrasad 684f906
change rule
AbhiPrasad d26de38
fix dangerfile
AbhiPrasad d2ba5fc
more logic around danger
AbhiPrasad 269c81c
remove eslint danger
AbhiPrasad 9dca0d8
never mind
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# THIS IS A TEMPORARY FILE | ||
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE | ||
|
||
packages/apm/**/* | ||
packages/core/**/* | ||
packages/ember/**/* | ||
packages/gatsby/**/* | ||
packages/hub/**/* | ||
packages/integrations/**/* | ||
packages/minimal/**/* | ||
packages/node/**/* | ||
packages/react/**/* | ||
packages/tracing/**/* | ||
packages/types/**/* | ||
packages/typescript/**/* | ||
packages/utils/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
}, | ||
extends: ['prettier', 'eslint:recommended'], | ||
plugins: ['sentry-sdk', 'jsdoc'], | ||
ignorePatterns: ['eslint-plugin-sentry-sdk'], | ||
overrides: [ | ||
{ | ||
// Configuration for JavaScript files | ||
files: ['*.js'], | ||
rules: { | ||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], | ||
}, | ||
}, | ||
{ | ||
// Configuration for typescript files | ||
files: ['*.ts', '*.tsx', '*.d.ts'], | ||
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'], | ||
plugins: ['@typescript-eslint'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
}, | ||
rules: { | ||
// Unused variables should be removed unless they are marked with and underscore (ex. _varName). | ||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], | ||
|
||
// Make sure that all ts-ignore comments are given a description. | ||
'@typescript-eslint/ban-ts-comment': [ | ||
'warn', | ||
{ | ||
'ts-ignore': 'allow-with-description', | ||
}, | ||
], | ||
|
||
// Types usage should be explicit as possible, so we prevent usage of inferrable types. | ||
// This is especially important because we have a public API, so usage needs to be as | ||
// easy to understand as possible. | ||
'@typescript-eslint/no-inferrable-types': 'off', | ||
|
||
// Enforce type annotations to maintain consistency. This is especially important as | ||
// we have a public API, so we want changes to be very explicit. | ||
'@typescript-eslint/typedef': ['error', { arrowParameter: false }], | ||
'@typescript-eslint/explicit-function-return-type': 'error', | ||
|
||
// Consistent ordering of fields, methods and constructors for classes should be enforced | ||
'@typescript-eslint/member-ordering': 'error', | ||
|
||
// Enforce that unbound methods are called within an expected scope. As we frequently pass data between classes | ||
// in SDKs, we should make sure that we are correctly preserving class scope. | ||
'@typescript-eslint/unbound-method': 'error', | ||
|
||
// Private and protected members of a class should be prefixed with a leading underscore | ||
'@typescript-eslint/naming-convention': [ | ||
'error', | ||
{ | ||
selector: 'memberLike', | ||
modifiers: ['private'], | ||
format: ['camelCase'], | ||
leadingUnderscore: 'require', | ||
}, | ||
{ | ||
selector: 'memberLike', | ||
modifiers: ['protected'], | ||
format: ['camelCase'], | ||
leadingUnderscore: 'require', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
// Configuration for files under src | ||
files: ['src/**/*'], | ||
rules: { | ||
// We want to prevent async await usage in our files to prevent uncessary bundle size. | ||
'sentry-sdk/no-async-await': 'error', | ||
|
||
// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation, | ||
// even if it may seems excessive at times, is important to emphasize. Turned off in tests. | ||
'jsdoc/require-jsdoc': [ | ||
'error', | ||
{ require: { ClassDeclaration: true, MethodDefinition: true }, checkConstructors: false }, | ||
], | ||
}, | ||
}, | ||
{ | ||
// Configuration for test files | ||
env: { | ||
jest: true, | ||
}, | ||
files: ['*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'], | ||
rules: { | ||
'max-lines': 'off', | ||
}, | ||
}, | ||
{ | ||
// Configuration for config files like webpack/rollback | ||
files: ['*.config.js'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2018, | ||
}, | ||
}, | ||
], | ||
|
||
rules: { | ||
// We want to prevent usage of unary operators outside of for loops | ||
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], | ||
|
||
// Disallow usage of console and alert | ||
'no-console': 'error', | ||
'no-alert': 'error', | ||
|
||
// Prevent reassignment of function parameters, but still allow object properties to be | ||
// reassigned. We want to enforce immutability when possible, but we shouldn't sacrifice | ||
// too much efficiency | ||
'no-param-reassign': ['error', { props: false }], | ||
|
||
// Prefer use of template expression over string literal concatenation | ||
'prefer-template': 'error', | ||
|
||
// Limit maximum file size to reduce complexity. Turned off in tests. | ||
'max-lines': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": ["esbenp.prettier-vscode", "ms-vscode.vscode-typescript-tslint-plugin"] | ||
"recommendations": ["esbenp.prettier-vscode", "ms-vscode.vscode-typescript-tslint-plugin", "dbaeumer.vscode-eslint"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This is a temporary file. It will be removed when we migrate | ||
// the eslint configs to another repo. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Rule to disallow usage of async await | ||
* @author Abhijeet Prasad | ||
*/ | ||
const noAsyncAwait = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Disallow usage of async await', | ||
category: 'Best Practices', | ||
recommended: true, | ||
}, | ||
fixable: null, | ||
schema: [], | ||
}, | ||
create: function(context) { | ||
return { | ||
FunctionDeclaration(node) { | ||
if (node.async) { | ||
context.report({ | ||
node, | ||
message: | ||
'Using async-await can add a lot to bundle size. Please do not use it outside of tests, use Promises instead', | ||
}); | ||
} | ||
}, | ||
|
||
ArrowFunctionExpression(node) { | ||
if (node.async) { | ||
context.report({ | ||
node, | ||
message: | ||
'Using async-await can add a lot to bundle size. Please do not use it outside of tests, use Promises instead', | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
rules: { | ||
'no-async-await': noAsyncAwait, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "eslint-plugin-sentry-sdk", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"eslint": "^7.5.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,17 @@ | |
"@types/mocha": "^5.2.0", | ||
"@types/node": "^11.13.7", | ||
"@types/sinon": "^7.0.11", | ||
"@typescript-eslint/eslint-plugin": "^3.7.1", | ||
"@typescript-eslint/parser": "^3.7.1", | ||
"chai": "^4.1.2", | ||
"codecov": "^3.6.5", | ||
"danger": "^7.1.3", | ||
"danger-plugin-eslint": "^0.1.0", | ||
"danger-plugin-tslint": "^2.0.0", | ||
"eslint": "^7.5.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-jsdoc": "^30.0.3", | ||
"eslint-plugin-sentry-sdk": "file:./eslint-plugin-sentry-sdk", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these dependencies are temporary. When we move the main |
||
"jest": "^24.7.1", | ||
"karma-browserstack-launcher": "^1.5.1", | ||
"karma-firefox-launcher": "^1.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
es6: true, | ||
browser: true, | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
}, | ||
extends: ['../../.eslintrc.js'], | ||
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*', 'src/loader.js'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx', '*.d.ts'], | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
}, | ||
}, | ||
{ | ||
files: ['test/**/*'], | ||
rules: { | ||
'jsdoc/require-jsdoc': 'off', | ||
'no-console': 'off', | ||
'max-lines': 'off', | ||
'prefer-template': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['test/integration/**/*'], | ||
env: { | ||
mocha: true, | ||
}, | ||
rules: { | ||
'no-undef': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['test/integration/common/**/*', 'test/integration/suites/**/*'], | ||
rules: { | ||
'no-unused-vars': 'off', | ||
}, | ||
}, | ||
], | ||
rules: { | ||
'no-prototype-builtins': 'off', | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we still need this?
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.
Yes, because the other packages still use
tslint
. We can remove after we are done.