Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 0 additions & 14 deletions packages/eslint-plugin/rules/__tests__/no-i18n-in-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function render() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -103,7 +102,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -116,7 +114,6 @@ const save = () => {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -129,7 +126,6 @@ const save = function() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -142,7 +138,6 @@ export default function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -157,7 +152,6 @@ const settings = {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -170,7 +164,6 @@ const settings = {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -183,7 +176,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -197,7 +189,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -211,7 +202,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -228,7 +218,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -243,11 +232,9 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand All @@ -262,7 +249,6 @@ function save() {
errors: [
{
messageId: 'noI18nInSave',
type: 'CallExpression',
},
],
},
Expand Down
5 changes: 0 additions & 5 deletions packages/eslint-plugin/rules/__tests__/no-unsafe-wp-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ruleTester.run( 'no-unsafe-wp-apis', rule, {
{
message: `Usage of \`__experimentalUnsafe\` from \`@wordpress/package\` is not allowed.
See https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/#experimental-and-unstable-apis for details.`,
type: 'ImportSpecifier',
},
],
},
Expand All @@ -75,7 +74,6 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
{
message: `Usage of \`__experimentalSafe\` from \`@wordpress/unsafe\` is not allowed.
See https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/#experimental-and-unstable-apis for details.`,
type: 'ImportSpecifier',
},
],
},
Expand All @@ -86,7 +84,6 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
{
message: `Usage of \`__experimentalSafe\` from \`@wordpress/unsafe\` is not allowed.
See https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/#experimental-and-unstable-apis for details.`,
type: 'ImportSpecifier',
},
],
},
Expand All @@ -97,7 +94,6 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
{
message: `Usage of \`__experimentalUnsafe\` from \`@wordpress/package\` is not allowed.
See https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/#experimental-and-unstable-apis for details.`,
type: 'ImportSpecifier',
},
],
},
Expand All @@ -108,7 +104,6 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
{
message: `Usage of \`__unstableFeature\` from \`@wordpress/package\` is not allowed.
See https://developer.wordpress.org/block-editor/contributors/develop/coding-guidelines/#experimental-and-unstable-apis for details.`,
type: 'ImportSpecifier',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ruleTester.run( 'use-recommended-components', rule, {
{
message:
'`SomeComponent` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
type: 'ImportSpecifier',
},
],
},
Expand All @@ -51,12 +50,10 @@ ruleTester.run( 'use-recommended-components', rule, {
{
message:
'`Foo` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
type: 'ImportSpecifier',
},
{
message:
'`Bar` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
type: 'ImportSpecifier',
},
],
},
Expand All @@ -67,7 +64,6 @@ ruleTester.run( 'use-recommended-components', rule, {
{
message:
'__experimentalZStack is planned for deprecation. Write your own CSS instead.',
type: 'ImportSpecifier',
},
],
},
Expand All @@ -77,7 +73,6 @@ ruleTester.run( 'use-recommended-components', rule, {
{
message:
'__experimentalZStack is planned for deprecation. Write your own CSS instead.',
type: 'ImportSpecifier',
},
],
},
Expand Down
13 changes: 8 additions & 5 deletions packages/eslint-plugin/rules/data-no-store-string-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function arrayLast( array ) {
function getReferences( context, specifiers ) {
const variables = specifiers.reduce(
( acc, specifier ) =>
acc.concat( context.getDeclaredVariables( specifier ) ),
acc.concat( context.sourceCode.getDeclaredVariables( specifier ) ),
[]
);
const references = variables.reduce(
Expand All @@ -58,7 +58,9 @@ function collectAllNodesFromCallbackFunctions( context, node ) {
( acc, { identifier: { parent } } ) =>
parent && parent.arguments && parent.arguments.length > 0
? acc.concat(
context.getDeclaredVariables( parent.arguments[ 0 ] )
context.sourceCode.getDeclaredVariables(
parent.arguments[ 0 ]
)
)
: acc,
[]
Expand Down Expand Up @@ -153,9 +155,10 @@ function getFixes( fixer, context, callNode ) {
fixer.replaceText( callNode.arguments[ 0 ], variableName ),
];

const imports = context
.getAncestors()[ 0 ]
.body.filter( ( node ) => node.type === 'ImportDeclaration' );
const ancestors = context.sourceCode.getAncestors( callNode );
const imports = ancestors[ 0 ].body.filter(
( node ) => node.type === 'ImportDeclaration'
);
const packageImports = imports.filter(
( node ) => node.source.value === importName
);
Expand Down
7 changes: 3 additions & 4 deletions packages/eslint-plugin/rules/dependency-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = {
},
create( context ) {
const mode = context.options[ 0 ] || 'always';
const comments = context.getSourceCode().getAllComments();
const sourceCode = context.sourceCode;
const comments = sourceCode.getAllComments();

/**
* Locality classification of an import, one of "External",
Expand Down Expand Up @@ -194,9 +195,7 @@ module.exports = {
return null;
}

const text = context
.getSourceCode()
.getText();
const text = sourceCode.getText();

// Trim preceding and trailing newlines.
let [ start, end ] = comment.range;
Expand Down
8 changes: 6 additions & 2 deletions packages/eslint-plugin/rules/i18n-translator-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function extractTranslatorKeys( commentText ) {
module.exports = {
meta: {
type: 'problem',
schema: [],
messages: {
missing:
'Translation function with placeholders is missing preceding translator comment',
Expand All @@ -71,6 +72,7 @@ module.exports = {
},
},
create( context ) {
const sourceCode = context.sourceCode;
return {
CallExpression( node ) {
const {
Expand Down Expand Up @@ -107,7 +109,7 @@ module.exports = {
return;
}

const comments = context.getCommentsBefore( node ).slice();
const comments = sourceCode.getCommentsBefore( node ).slice();

let parentNode = parent;

Expand All @@ -123,7 +125,9 @@ module.exports = {
parentNode.type !== 'Program' &&
Math.abs( parentNode.loc.start.line - currentLine ) <= 1
) {
comments.push( ...context.getCommentsBefore( parentNode ) );
comments.push(
...sourceCode.getCommentsBefore( parentNode )
);
parentNode = parentNode.parent;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/rules/no-i18n-in-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
},
create( context ) {
let saveFunctionDepth = 0;
const filename = context.getFilename();
const filename = context.filename;

// Skip deprecated files as they preserve old behavior including translation functions
const normalizedFilename = filename.replace( /\\/g, '/' );
Expand Down
13 changes: 7 additions & 6 deletions packages/eslint-plugin/rules/no-unused-vars-before-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
const FUNCTION_SCOPE_JSX_IDENTIFIERS = new WeakMap();

/**
* Returns the closest function scope for the current ESLint context object, or
* undefined if it cannot be determined.
* Returns the closest function scope for the given node, or undefined if it
* cannot be determined.
*
* @param {ESLintRuleContext} context ESLint context object.
* @param {ESTreeNode} node Current AST node.
*
* @return {ESLintScope|undefined} Function scope, if known.
*/
function getClosestFunctionScope( context ) {
let functionScope = context.getScope();
function getClosestFunctionScope( context, node ) {
let functionScope = context.sourceCode.getScope( node );
while ( functionScope.type !== 'function' && functionScope.upper ) {
functionScope = functionScope.upper;
}
Expand Down Expand Up @@ -73,7 +74,7 @@ module.exports = /** @type {import('eslint').Rule} */ ( {
// identifiers. Account for this by visiting JSX identifiers
// first, and tracking them in a map per function scope, which
// is later merged with the known variable references.
const functionScope = getClosestFunctionScope( context );
const functionScope = getClosestFunctionScope( context, node );
if ( ! functionScope ) {
return;
}
Expand All @@ -88,7 +89,7 @@ module.exports = /** @type {import('eslint').Rule} */ ( {
FUNCTION_SCOPE_JSX_IDENTIFIERS.get( functionScope ).add( node );
},
'ReturnStatement:exit'( node ) {
const functionScope = getClosestFunctionScope( context );
const functionScope = getClosestFunctionScope( context, node );
if ( ! functionScope ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/rules/react-no-unsafe-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
// Consider whether `setTimeout` is a reference to the global
// by checking references to see if `setTimeout` resolves to a
// variable in scope.
const { references } = context.getScope();
const { references } = context.sourceCode.getScope( node );
const hasResolvedReference = references.some(
( reference ) =>
reference.identifier.name === 'setTimeout' &&
Expand Down
Loading