forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-was-shown-methods.js
36 lines (33 loc) · 1.14 KB
/
check-was-shown-methods.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @type {import('eslint').Rule.RuleModule}
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Checks wasShown() method definitions call super.wasShown();',
category: 'Possible Errors',
},
fixable: 'code',
schema: [] // no options
},
create: function(context) {
return {
MethodDefinition(node) {
const nodeName = node.key.name;
if (node.parent.parent.superClass?.property?.name === 'Widget' && nodeName === 'wasShown') {
const topBodyNode = node.value.body.body[0];
if (!(topBodyNode.type === 'ExpressionStatement' && topBodyNode.expression.type === 'CallExpression' &&
topBodyNode.expression.callee.object.type === 'Super' &&
topBodyNode.expression.callee.property.name === 'wasShown')) {
context.report({node, message: 'Please make sure the first call in wasShown is to super.wasShown().'});
}
}
}
};
}
};