Skip to content

Commit f3f26aa

Browse files
authored
Update eslint rules (#14268)
* Update eslint rules * Link fix
1 parent 7049770 commit f3f26aa

File tree

9 files changed

+37
-41
lines changed

9 files changed

+37
-41
lines changed

.eslintrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"ignoreUrls": true
7171
}
7272
],
73+
"no-await-in-loop": "off",
7374
"no-confusing-arrow": [
7475
"error",
7576
{
@@ -82,6 +83,22 @@
8283
"no-multi-str": "off",
8384
"no-param-reassign": "off",
8485
"no-prototype-builtins": "off",
86+
"no-restricted-syntax": [
87+
"error",
88+
{
89+
"selector": "ForInStatement",
90+
"message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array."
91+
},
92+
93+
{
94+
"selector": "LabeledStatement",
95+
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
96+
},
97+
{
98+
"selector": "WithStatement",
99+
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
100+
}
101+
],
85102
"no-template-curly-in-string": "off",
86103
"no-underscore-dangle": "off",
87104
"no-useless-escape": "off",

src/client/pythonEnvironments/base/locatorUtils.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export function getQueryFilter(query: PythonLocatorQuery): (env: PythonEnvInfo)
3838
if (env.searchLocation === undefined) {
3939
// It is not a "rooted" env.
4040
return includeNonRooted;
41-
} else {
42-
// It is a "rooted" env.
43-
const loc = env.searchLocation;
44-
if (locationFilters !== undefined) {
45-
// Check against the requested roots. (There may be none.)
46-
return locationFilters.some((filter) => filter(loc));
47-
}
48-
return true;
4941
}
42+
// It is a "rooted" env.
43+
const loc = env.searchLocation;
44+
if (locationFilters !== undefined) {
45+
// Check against the requested roots. (There may be none.)
46+
return locationFilters.some((filter) => filter(loc));
47+
}
48+
return true;
5049
}
5150
return (env) => {
5251
if (!checkKind(env)) {
@@ -101,7 +100,6 @@ export async function getEnvs(iterator: IPythonEnvsIterator): Promise<PythonEnvI
101100
let result = await iterator.next();
102101
while (!result.done) {
103102
envs.push(result.value);
104-
// eslint-disable-next-line no-await-in-loop
105103
result = await iterator.next();
106104
}
107105

src/client/pythonEnvironments/base/locators/composite/environmentsReducer.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export class PythonEnvsReducer implements ILocator {
3838
if (areSameEnv(result.value, env)) {
3939
environment = result.value;
4040
}
41-
// eslint-disable-next-line no-await-in-loop
4241
result = await iterator.next();
4342
}
4443
if (!environment) {
@@ -72,15 +71,13 @@ async function* iterEnvsIterator(
7271
if (event === null) {
7372
state.done = true;
7473
checkIfFinishedAndNotify(state, didUpdate);
74+
} else if (seen[event.index] !== undefined) {
75+
state.pending += 1;
76+
resolveDifferencesInBackground(event.index, event.update, state, didUpdate, seen)
77+
.ignoreErrors();
7578
} else {
76-
if (seen[event.index] !== undefined) {
77-
state.pending += 1;
78-
resolveDifferencesInBackground(event.index, event.update, state, didUpdate, seen)
79-
.ignoreErrors();
80-
} else {
81-
// This implies a problem in a downstream locator
82-
traceVerbose(`Expected already iterated env, got ${event.old} (#${event.index})`);
83-
}
79+
// This implies a problem in a downstream locator
80+
traceVerbose(`Expected already iterated env, got ${event.old} (#${event.index})`);
8481
}
8582
});
8683
}
@@ -97,7 +94,6 @@ async function* iterEnvsIterator(
9794
yield currEnv;
9895
seen.push(currEnv);
9996
}
100-
// eslint-disable-next-line no-await-in-loop
10197
result = await iterator.next();
10298
}
10399
if (iterator.onUpdated === undefined) {

src/client/pythonEnvironments/base/locators/composite/environmentsResolver.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ export class PythonEnvsResolver implements ILocator {
6161
if (event === null) {
6262
state.done = true;
6363
checkIfFinishedAndNotify(state, didUpdate);
64+
} else if (seen[event.index] !== undefined) {
65+
seen[event.index] = event.update;
66+
state.pending += 1;
67+
this.resolveInBackground(event.index, state, didUpdate, seen)
68+
.ignoreErrors();
6469
} else {
65-
if (seen[event.index] !== undefined) {
66-
seen[event.index] = event.update;
67-
state.pending += 1;
68-
this.resolveInBackground(event.index, state, didUpdate, seen)
69-
.ignoreErrors();
70-
} else {
71-
// This implies a problem in a downstream locator
72-
traceVerbose(`Expected already iterated env, got ${event.old} (#${event.index})`);
73-
}
70+
// This implies a problem in a downstream locator
71+
traceVerbose(`Expected already iterated env, got ${event.old} (#${event.index})`);
7472
}
7573
});
7674
}
@@ -82,7 +80,6 @@ export class PythonEnvsResolver implements ILocator {
8280
yield currEnv;
8381
state.pending += 1;
8482
this.resolveInBackground(seen.indexOf(currEnv), state, didUpdate, seen).ignoreErrors();
85-
// eslint-disable-next-line no-await-in-loop
8683
result = await iterator.next();
8784
}
8885
if (iterator.onUpdated === undefined) {

src/client/pythonEnvironments/common/environmentIdentifier.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ function getIdentifiers(): Map<EnvironmentType, (path:string) => Promise<boolean
7575
export async function identifyEnvironment(interpreterPath: string): Promise<EnvironmentType> {
7676
const identifiers = getIdentifiers();
7777
const prioritizedEnvTypes = getPrioritizedEnvironmentType();
78-
// eslint-disable-next-line no-restricted-syntax
7978
for (const e of prioritizedEnvTypes) {
8079
const identifier = identifiers.get(e);
81-
// eslint-disable-next-line no-await-in-loop
8280
if (identifier && await identifier(interpreterPath)) {
8381
return e;
8482
}

src/client/pythonEnvironments/discovery/locators/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ export class WorkspaceLocators extends Locator {
130130
// Fall back to checking all the roots.
131131
// The eslint disable below should be removed after we have a
132132
// better solution for these. We need asyncFind for this.
133-
// eslint-disable-next-line no-restricted-syntax
134133
for (const key of Object.keys(this.locators)) {
135-
// eslint-disable-next-line no-await-in-loop
136134
const resolved = await this.locators[key].resolveEnv(env);
137135
if (resolved !== undefined) {
138136
return resolved;

src/client/pythonEnvironments/discovery/locators/services/pipEnvHelper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export async function _getAssociatedPipfile(
3535
let heightToSearch = options.lookIntoParentDirectories ? getSearchHeight() : 1;
3636
while (heightToSearch > 0 && !arePathsSame(searchDir, path.dirname(searchDir))) {
3737
const pipFile = path.join(searchDir, pipFileName);
38-
// eslint-disable-next-line no-await-in-loop
3938
if (await pathExists(pipFile)) {
4039
return pipFile;
4140
}

src/client/pythonEnvironments/discovery/locators/services/posixKnownPathsLocator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ import { commonPosixBinPaths, isPosixPythonBin } from '../../../common/posixUtil
1818
async function getPythonBinFromKnownPaths(): Promise<string[]> {
1919
const knownPaths = await commonPosixBinPaths();
2020
const pythonBins:Set<string> = new Set();
21-
// eslint-disable-next-line no-restricted-syntax
2221
for (const knownPath of knownPaths) {
23-
// eslint-disable-next-line no-await-in-loop
2422
const files = (await fsapi.readdir(knownPath))
2523
.map((filename:string) => path.join(knownPath, filename))
2624
.filter(isPosixPythonBin);
2725

28-
// eslint-disable-next-line no-restricted-syntax
2926
for (const file of files) {
3027
// Ensure that we have a collection of unique global binaries by
3128
// resolving all symlinks to the target binaries.
3229
try {
33-
// eslint-disable-next-line no-await-in-loop
3430
const resolvedBin = await resolveSymbolicLink(file);
3531
pythonBins.add(resolvedBin);
3632
traceInfo(`Found: ${file} --> ${resolvedBin}`);

src/client/pythonEnvironments/discovery/subenv.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import { EnvironmentType } from '../info';
55
import { getPyenvTypeFinder } from './globalenv';
66

7-
// tslint:disable-next-line: no-single-line-block-comment
8-
/* eslint-disable no-await-in-loop, no-restricted-syntax */
9-
107
type ExecFunc = (cmd: string, args: string[]) => Promise<{ stdout: string }>;
118

129
type NameFinderFunc = (python: string) => Promise<string | undefined>;

0 commit comments

Comments
 (0)