-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
tslint to eslint migration #87644
Merged
Merged
tslint to eslint migration #87644
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
556475c
add eslint-rules "module" and use it in eslintrc-file
jrieken ce0d705
add package.json script
jrieken 31d049f
use (most of) generated eslintrc-file
jrieken 21bc306
script run check JS and TS files
jrieken d0e72fe
ignore generated files
jrieken a104742
use single eslintrc-file for extensions/ and src/, no type check rules
jrieken c5e6c9a
Merge branch 'master' into joh/eslint-rules
jrieken 0aa8604
Merge branch 'master' into joh/eslint-rules
jrieken 1075b91
tweaks
jrieken b0d3805
use rulesdir instead of rules-module
jrieken 9819da6
migrate import-patterns rule to eslint
jrieken 291ee00
add no-buffer-ctor rule
jrieken a7ca3a5
rulesdir/rulePaths for gulp-eslint
jrieken 54d2030
tweak rules and excludes
jrieken 1dbc699
Merge branch 'master' into joh/eslint-rules
jrieken a3bd604
migrate translation remind rule
jrieken 2ea9132
migrate no-nls-in-standalone-editor rule
jrieken b05b481
migrate no-standalone-editor rule
jrieken 808865c
extract import path detection into util
jrieken 11f9af0
check call expression argument length
jrieken 4db8006
use ts-es-tree-typings, support import-equals
jrieken 53d1dff
use AST selector to simplify things
jrieken a61f38e
migrate no-unexternalized-strings rule (have two variants)
jrieken c9179d1
fix nls-rule when using member-expression
jrieken 9fefd2b
relax and allow double quoted strings appearing inside localize call
jrieken f885d77
remove unused dependency
jrieken e27d7ca
only one double-qoute string rule
jrieken 600fded
correctly configure rule paths in hygiene task
jrieken f16368c
Merge branch 'master' into joh/eslint-rules
jrieken dc84c71
update 'gulp eslint' and 'gulp hygiene' so that eslint also seens TS …
jrieken 2bd1595
tweak ignore file
jrieken 50d16a3
add rulePaths-option for eslint extension
jrieken 324764a
cleanup rule meta data, add links when possible
jrieken e6d9b41
makes eslint fail the hygiene checks
jrieken e22be57
add disabled rules for being more complete with our tslint config...
jrieken d8b6b05
Merge branch 'master' into joh/eslint-rules
jrieken ee4dccd
disable tslint in hygiene check
jrieken 856d085
run "eslint --fix" to get some changes for free
jrieken 90512e6
tslint default severity is OFF
jrieken f80a6f9
update rule-disablements (eslint-disable for tslint-disable)
jrieken 84013e2
fix double quote issues
jrieken 2141437
fix eslint issues in build/gulpfile.*
jrieken 80e6e42
adjust rule to allow double quotes for "use strict" and other directives
jrieken 2a71a96
also disable tslint for build-folder
jrieken d18119e
enable jsdoc/no-types rule for TS files
jrieken 12eb715
(re)enable no-extra-semi rule
jrieken 769bbe2
remove tslint.json files
jrieken 09ee89c
remove more unused tslint directives
jrieken 37b071f
remove custom tslint rules
jrieken ca8a717
tslint removal
jrieken 125ba4a
enable custom/forked no-unused-expressions rule
jrieken 1864915
add eslint task definition
jrieken 874a037
Merge branch 'master' into joh/eslint-rules
jrieken 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
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,145 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// FORKED FROM https://github.com/eslint/eslint/blob/b23ad0d789a909baf8d7c41a35bc53df932eaf30/lib/rules/no-unused-expressions.js | ||
// and added support for `OptionalCallExpression`, see https://github.com/facebook/create-react-app/issues/8107 and https://github.com/eslint/eslint/issues/12642 | ||
|
||
/** | ||
* @fileoverview Flag expressions in statement position that do not side effect | ||
* @author Michael Ficarra | ||
*/ | ||
|
||
'use strict'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
|
||
docs: { | ||
description: 'disallow unused expressions', | ||
category: 'Best Practices', | ||
recommended: false, | ||
url: 'https://eslint.org/docs/rules/no-unused-expressions' | ||
}, | ||
|
||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
allowShortCircuit: { | ||
type: 'boolean', | ||
default: false | ||
}, | ||
allowTernary: { | ||
type: 'boolean', | ||
default: false | ||
}, | ||
allowTaggedTemplates: { | ||
type: 'boolean', | ||
default: false | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
] | ||
}, | ||
|
||
create(context) { | ||
const config = context.options[0] || {}, | ||
allowShortCircuit = config.allowShortCircuit || false, | ||
allowTernary = config.allowTernary || false, | ||
allowTaggedTemplates = config.allowTaggedTemplates || false; | ||
|
||
// eslint-disable-next-line jsdoc/require-description | ||
/** | ||
* @param {ASTNode} node any node | ||
* @returns {boolean} whether the given node structurally represents a directive | ||
*/ | ||
function looksLikeDirective(node) { | ||
return node.type === 'ExpressionStatement' && | ||
node.expression.type === 'Literal' && typeof node.expression.value === 'string'; | ||
} | ||
|
||
// eslint-disable-next-line jsdoc/require-description | ||
/** | ||
* @param {Function} predicate ([a] -> Boolean) the function used to make the determination | ||
* @param {a[]} list the input list | ||
* @returns {a[]} the leading sequence of members in the given list that pass the given predicate | ||
*/ | ||
function takeWhile(predicate, list) { | ||
for (let i = 0; i < list.length; ++i) { | ||
if (!predicate(list[i])) { | ||
return list.slice(0, i); | ||
} | ||
} | ||
return list.slice(); | ||
} | ||
|
||
// eslint-disable-next-line jsdoc/require-description | ||
/** | ||
* @param {ASTNode} node a Program or BlockStatement node | ||
* @returns {ASTNode[]} the leading sequence of directive nodes in the given node's body | ||
*/ | ||
function directives(node) { | ||
return takeWhile(looksLikeDirective, node.body); | ||
} | ||
|
||
// eslint-disable-next-line jsdoc/require-description | ||
/** | ||
* @param {ASTNode} node any node | ||
* @param {ASTNode[]} ancestors the given node's ancestors | ||
* @returns {boolean} whether the given node is considered a directive in its current position | ||
*/ | ||
function isDirective(node, ancestors) { | ||
const parent = ancestors[ancestors.length - 1], | ||
grandparent = ancestors[ancestors.length - 2]; | ||
|
||
return (parent.type === 'Program' || parent.type === 'BlockStatement' && | ||
(/Function/u.test(grandparent.type))) && | ||
directives(parent).indexOf(node) >= 0; | ||
} | ||
|
||
/** | ||
* Determines whether or not a given node is a valid expression. Recurses on short circuit eval and ternary nodes if enabled by flags. | ||
* @param {ASTNode} node any node | ||
* @returns {boolean} whether the given node is a valid expression | ||
*/ | ||
function isValidExpression(node) { | ||
if (allowTernary) { | ||
|
||
// Recursive check for ternary and logical expressions | ||
if (node.type === 'ConditionalExpression') { | ||
return isValidExpression(node.consequent) && isValidExpression(node.alternate); | ||
} | ||
} | ||
|
||
if (allowShortCircuit) { | ||
if (node.type === 'LogicalExpression') { | ||
return isValidExpression(node.right); | ||
} | ||
} | ||
|
||
if (allowTaggedTemplates && node.type === 'TaggedTemplateExpression') { | ||
return true; | ||
} | ||
|
||
return /^(?:Assignment|OptionalCall|Call|New|Update|Yield|Await)Expression$/u.test(node.type) || | ||
(node.type === 'UnaryExpression' && ['delete', 'void'].indexOf(node.operator) >= 0); | ||
} | ||
|
||
return { | ||
ExpressionStatement(node) { | ||
if (!isValidExpression(node.expression) && !isDirective(node, context.getAncestors())) { | ||
context.report({ node, message: 'Expected an assignment or function call and instead saw an expression.' }); | ||
} | ||
} | ||
}; | ||
|
||
} | ||
}; |
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 |
---|---|---|
|
@@ -180,7 +180,7 @@ export class TextFileSaveErrorHandler extends Disposable implements ISaveErrorHa | |
// Show message and keep function to hide in case the file gets saved/reverted | ||
const actions: INotificationActions = { primary: primaryActions, secondary: secondaryActions }; | ||
const handle = this.notificationService.notify({ severity: Severity.Error, message, actions }); | ||
Event.once(handle.onDidClose)(() => { dispose(primaryActions), dispose(secondaryActions); }); | ||
Event.once(handle.onDidClose)(() => { dispose(primaryActions); dispose(secondaryActions); }); | ||
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. fyi @mjbvz |
||
this.messages.set(model.resource, handle); | ||
} | ||
|
||
|
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.
fyi @sandy081
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.
Good catch by the linter