mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 04:26:32 +08:00
Bug: 1106746 Change-Id: I373793016ce59308d1cde1b8cb7f15989d298ecc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2988318 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Kriti Sapra <kritisapra@google.com>
109 lines
2.8 KiB
JavaScript
109 lines
2.8 KiB
JavaScript
// Copyright 2021 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';
|
|
|
|
const rule = require('../lib/check_was_shown_methods.js');
|
|
const ruleTester = new (require('eslint').RuleTester)({
|
|
parserOptions: {ecmaVersion: 9, sourceType: 'module'},
|
|
parser: require.resolve('@typescript-eslint/parser'),
|
|
});
|
|
|
|
const EXPECTED_ERROR_MESSAGE = 'Please make sure the first call in wasShown is to super.wasShown().';
|
|
|
|
ruleTester.run('check_was_shown_methods', rule, {
|
|
valid: [
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
super.wasShown();
|
|
if (typeof this._frameIndex === 'number') {
|
|
this._server.notifyViewShown(this._id, this._frameIndex);
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
},
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
super.wasShown();
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
},
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
super.wasShown();
|
|
this.shadowRoot.adoptedStyleSheets = [componentStyles];
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
},
|
|
{
|
|
code: `
|
|
export class Component extends HTMLElement {
|
|
wasShown(): void {
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts'
|
|
},
|
|
{
|
|
code: `
|
|
export class CharacterIdMap<T> {
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts'
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
if (typeof this._frameIndex === 'number') {
|
|
this._server.notifyViewShown(this._id, this._frameIndex);
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
errors: [{message: EXPECTED_ERROR_MESSAGE}]
|
|
},
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
if (typeof this._frameIndex === 'number') {
|
|
this._server.notifyViewShown(this._id, this._frameIndex);
|
|
}
|
|
super.wasShown();
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
errors: [{message: EXPECTED_ERROR_MESSAGE}]
|
|
},
|
|
{
|
|
code: `
|
|
export class Component extends UI.Widget.Widget {
|
|
wasShown(): void {
|
|
this.shadowRoot.adoptedStyleSheets = [componentStyles];
|
|
super.wasShown();
|
|
}
|
|
}
|
|
`,
|
|
filename: 'front_end/components/test.ts',
|
|
errors: [{message: EXPECTED_ERROR_MESSAGE}]
|
|
}
|
|
]
|
|
});
|