Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): support eslint@5#2917

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 1 commit intotypescript-eslint:masterfromSimenB:eslint-5-compat
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
1 change: 1 addition & 0 deletionspackages/eslint-plugin/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,7 @@
"@typescript-eslint/scope-manager":"4.12.0",
"debug":"^4.1.1",
"functional-red-black-tree":"^1.0.1",
"lodash":"^4.17.15",
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@typescript-eslint/eslint-plugin-tslint and@typescript-eslint/typescript-estree already depend on it, so shouldn't make a difference

"regexpp":"^3.0.0",
"semver":"^7.3.2",
"tsutils":"^3.17.1"
Expand Down
39 changes: 1 addition & 38 deletionspackages/eslint-plugin/src/rules/no-redeclare.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,43 +13,6 @@ type Options = [
},
];

// https://github.com/lodash/lodash/blob/86a852fe763935bb64c12589df5391fd7d3bb14d/escapeRegExp.js
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
const reHasRegExpChar = RegExp(reRegExpChar.source);
function escapeRegExp(str: string): string {
return str && reHasRegExpChar.test(str)
? str.replace(reRegExpChar, '\\$&')
: str || '';
}

function getNameLocationInGlobalDirectiveComment(
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

my IDE "complained" about duplicate code, so I found this and just removed it

sourceCode: TSESLint.SourceCode,
comment: TSESTree.Comment,
name: string,
): TSESTree.SourceLocation {
const namePattern = new RegExp(
`[\\s,]${escapeRegExp(name)}(?:$|[\\s,:])`,
'gu',
);

// To ignore the first text "global".
namePattern.lastIndex = comment.value.indexOf('global') + 6;

// Search a given variable name.
const match = namePattern.exec(comment.value);

// Convert the index to loc.
const start = sourceCode.getLocFromIndex(
comment.range[0] + '/*'.length + (match ? match.index + 1 : 0),
);
const end = {
line: start.line,
column: start.column + (match ? name.length : 1),
};

return { start, end };
}

export default util.createRule<Options, MessageIds>({
name: 'no-redeclare',
meta: {
Expand DownExpand Up@@ -129,7 +92,7 @@ export default util.createRule<Options, MessageIds>({
yield {
type: 'comment',
node: comment,
loc: getNameLocationInGlobalDirectiveComment(
loc:util.getNameLocationInGlobalDirectiveComment(
sourceCode,
comment,
variable.name,
Expand Down
3 changes: 1 addition & 2 deletionspackages/eslint-plugin/src/rules/no-unused-vars.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@ import {
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { PatternVisitor } from '@typescript-eslint/scope-manager';
import { getNameLocationInGlobalDirectiveComment } from 'eslint/lib/rules/utils/ast-utils';
import * as util from '../util';

export type MessageIds = 'unusedVar';
Expand DownExpand Up@@ -388,7 +387,7 @@ export default util.createRule<Options, MessageIds>({

context.report({
node: programNode,
loc: getNameLocationInGlobalDirectiveComment(
loc:util.getNameLocationInGlobalDirectiveComment(
sourceCode,
directiveComment,
unusedVar.name,
Expand Down
41 changes: 41 additions & 0 deletionspackages/eslint-plugin/src/util/astUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';
import escapeRegExp from 'lodash/escapeRegExp';

// deeply re-export, for convenience
export * from '@typescript-eslint/experimental-utils/dist/ast-utils';

// The following is copied from `eslint`'s source code since it doesn't exist in eslint@5.
// https://github.com/eslint/eslint/blob/145aec1ab9052fbca96a44d04927c595951b1536/lib/rules/utils/ast-utils.js#L1751-L1779
// Could be export { getNameLocationInGlobalDirectiveComment } from 'eslint/lib/rules/utils/ast-utils'
/**
* Get the `loc` object of a given name in a `/*globals` directive comment.
* @param {SourceCode} sourceCode The source code to convert index to loc.
* @param {Comment} comment The `/*globals` directive comment which include the name.
* @param {string} name The name to find.
* @returns {SourceLocation} The `loc` object.
*/
export function getNameLocationInGlobalDirectiveComment(
sourceCode: TSESLint.SourceCode,
comment: TSESTree.Comment,
name: string,
): TSESTree.SourceLocation {
const namePattern = new RegExp(
`[\\s,]${escapeRegExp(name)}(?:$|[\\s,:])`,
'gu',
);

// To ignore the first text "global".
namePattern.lastIndex = comment.value.indexOf('global') + 6;

// Search a given variable name.
const match = namePattern.exec(comment.value);

// Convert the index to loc.
const start = sourceCode.getLocFromIndex(
comment.range[0] + '/*'.length + (match ? match.index + 1 : 0),
);
const end = {
line: start.line,
column: start.column + (match ? name.length : 1),
};

return { start, end };
}
14 changes: 0 additions & 14 deletionspackages/eslint-plugin/typings/eslint-rules.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -830,17 +830,3 @@ declare module 'eslint/lib/rules/prefer-const' {
>;
export = rule;
}

declare module 'eslint/lib/rules/utils/ast-utils' {
import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';

const utils: {
getNameLocationInGlobalDirectiveComment(
sourceCode: TSESLint.SourceCode,
comment: TSESTree.Comment,
name: string,
): TSESTree.SourceLocation;
};

export = utils;
}

[8]ページ先頭

©2009-2025 Movatter.jp