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

tslint to eslint migration #87644

Merged
merged 53 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
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 Dec 24, 2019
ce0d705
add package.json script
jrieken Dec 24, 2019
31d049f
use (most of) generated eslintrc-file
jrieken Dec 24, 2019
21bc306
script run check JS and TS files
jrieken Dec 24, 2019
d0e72fe
ignore generated files
jrieken Dec 24, 2019
a104742
use single eslintrc-file for extensions/ and src/, no type check rules
jrieken Dec 24, 2019
c5e6c9a
Merge branch 'master' into joh/eslint-rules
jrieken Dec 24, 2019
0aa8604
Merge branch 'master' into joh/eslint-rules
jrieken Dec 30, 2019
1075b91
tweaks
jrieken Dec 30, 2019
b0d3805
use rulesdir instead of rules-module
jrieken Dec 30, 2019
9819da6
migrate import-patterns rule to eslint
jrieken Dec 30, 2019
291ee00
add no-buffer-ctor rule
jrieken Dec 30, 2019
a7ca3a5
rulesdir/rulePaths for gulp-eslint
jrieken Dec 30, 2019
54d2030
tweak rules and excludes
jrieken Dec 30, 2019
1dbc699
Merge branch 'master' into joh/eslint-rules
jrieken Dec 30, 2019
a3bd604
migrate translation remind rule
jrieken Dec 30, 2019
2ea9132
migrate no-nls-in-standalone-editor rule
jrieken Dec 30, 2019
b05b481
migrate no-standalone-editor rule
jrieken Dec 30, 2019
808865c
extract import path detection into util
jrieken Dec 30, 2019
11f9af0
check call expression argument length
jrieken Dec 30, 2019
4db8006
use ts-es-tree-typings, support import-equals
jrieken Dec 30, 2019
53d1dff
use AST selector to simplify things
jrieken Dec 30, 2019
a61f38e
migrate no-unexternalized-strings rule (have two variants)
jrieken Dec 30, 2019
c9179d1
fix nls-rule when using member-expression
jrieken Dec 30, 2019
9fefd2b
relax and allow double quoted strings appearing inside localize call
jrieken Dec 30, 2019
f885d77
remove unused dependency
jrieken Dec 31, 2019
e27d7ca
only one double-qoute string rule
jrieken Dec 31, 2019
600fded
correctly configure rule paths in hygiene task
jrieken Dec 31, 2019
f16368c
Merge branch 'master' into joh/eslint-rules
jrieken Dec 31, 2019
dc84c71
update 'gulp eslint' and 'gulp hygiene' so that eslint also seens TS …
jrieken Dec 31, 2019
2bd1595
tweak ignore file
jrieken Dec 31, 2019
50d16a3
add rulePaths-option for eslint extension
jrieken Dec 31, 2019
324764a
cleanup rule meta data, add links when possible
jrieken Dec 31, 2019
e6d9b41
makes eslint fail the hygiene checks
jrieken Dec 31, 2019
e22be57
add disabled rules for being more complete with our tslint config...
jrieken Dec 31, 2019
d8b6b05
Merge branch 'master' into joh/eslint-rules
jrieken Jan 2, 2020
ee4dccd
disable tslint in hygiene check
jrieken Jan 2, 2020
856d085
run "eslint --fix" to get some changes for free
jrieken Jan 2, 2020
90512e6
tslint default severity is OFF
jrieken Jan 2, 2020
f80a6f9
update rule-disablements (eslint-disable for tslint-disable)
jrieken Jan 2, 2020
84013e2
fix double quote issues
jrieken Jan 2, 2020
2141437
fix eslint issues in build/gulpfile.*
jrieken Jan 2, 2020
80e6e42
adjust rule to allow double quotes for "use strict" and other directives
jrieken Jan 2, 2020
2a71a96
also disable tslint for build-folder
jrieken Jan 2, 2020
d18119e
enable jsdoc/no-types rule for TS files
jrieken Jan 2, 2020
12eb715
(re)enable no-extra-semi rule
jrieken Jan 2, 2020
769bbe2
remove tslint.json files
jrieken Jan 3, 2020
09ee89c
remove more unused tslint directives
jrieken Jan 3, 2020
37b071f
remove custom tslint rules
jrieken Jan 3, 2020
ca8a717
tslint removal
jrieken Jan 3, 2020
125ba4a
enable custom/forked no-unused-expressions rule
jrieken Jan 3, 2020
1864915
add eslint task definition
jrieken Jan 3, 2020
874a037
Merge branch 'master' into joh/eslint-rules
jrieken Jan 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
"no-sparse-arrays": "warn",
"no-throw-literal": "warn",
"no-unsafe-finally": "warn",
"no-unused-expressions": "off",
"no-unused-labels": "warn",
"no-var": "warn",
"jsdoc/no-types": "warn",
"semi": "off",
"@typescript-eslint/semi": "warn",
"@typescript-eslint/class-name-casing": "warn",
"code-no-unused-expressions": [
"warn",
{
"allowTernary": true
}
],
"code-translation-remind": "warn",
"code-no-nls-in-standalone-editor": "warn",
"code-no-standalone-editor": "warn",
Expand Down
145 changes: 145 additions & 0 deletions build/lib/eslint/code-no-unused-expressions.js
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.' });
}
}
};

}
};
2 changes: 1 addition & 1 deletion src/vs/platform/log/common/fileLogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class FileLoggerService extends Disposable implements ILoggerService {
getLogger(resource: URI): ILogger {
let logger = this.loggers.get(resource.toString());
if (!logger) {
logger = new BufferLogService, this.logService.getLevel();
logger = new BufferLogService(this.logService.getLevel());
Copy link
Member Author

Choose a reason for hiding this comment

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

fyi @sandy081

Copy link
Member

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

this.loggers.set(resource.toString(), logger);
whenProviderRegistered(resource, this.fileService).then(() => (<BufferLogService>logger).logger = this.instantiationService.createInstance(FileLogService, basename(resource), resource, this.logService.getLevel()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Copy link
Member Author

Choose a reason for hiding this comment

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

fyi @mjbvz

this.messages.set(model.resource, handle);
}

Expand Down