Manual fixes for eslint and typescript errors

Eslint 7 detects more problems than the previous versions. The
following problems were detected and manually fixed:

* gr-download-dialog_test.ts
  124:32  error  Optional chain expressions can return undefined by
  design - using a non-null assertion is unsafe and wrong
  @typescript-eslint/no-non-null-asserted-optional-chain

* gr-comment_test.js
  734:7  error  'flushAsynchronousOperations' is not defined  no-undef

* gr-dropdown-list.ts
  35:0  error  Tag @event must have a name/namepath  jsdoc/valid-types

* attention-set-util.ts
  49:30  error  Do not access Object.prototype method 'hasOwnProperty'
  from target object  no-prototype-builtins

Typescript 4.0.5 reports multiple errors in gr-change-metadata_test.ts
   error TS2790: The operand of a 'delete' operator must be optiona

Change-Id: Icd6c3e99d6e841510d5801199f8191d6a083dfc2
This commit is contained in:
Dmitrii Filippov
2020-12-22 18:22:00 +01:00
parent 73a4c6fec1
commit 3a2b235bce
6 changed files with 25 additions and 50 deletions

View File

@@ -85,7 +85,10 @@ module.exports = {
capIsNewExceptionPattern: '^.*Mixin$',
}],
// https://eslint.org/docs/rules/no-console
'no-console': ['error', {allow: ['warn', 'error', 'info', 'assert', 'group', 'groupEnd']}],
'no-console': [
'error',
{allow: ['warn', 'error', 'info', 'assert', 'group', 'groupEnd']},
],
// https://eslint.org/docs/rules/no-multiple-empty-lines
'no-multiple-empty-lines': ['error', {max: 1}],
// https://eslint.org/docs/rules/no-prototype-builtins
@@ -102,11 +105,13 @@ module.exports = {
'no-restricted-syntax': [
'error',
{
selector: 'ExpressionStatement > CallExpression > MemberExpression[object.name=\'test\'][property.name=\'only\']',
selector: 'ExpressionStatement > CallExpression > ' +
'MemberExpression[object.name=\'test\'][property.name=\'only\']',
message: 'Remove test.only.',
},
{
selector: 'ExpressionStatement > CallExpression > MemberExpression[object.name=\'suite\'][property.name=\'only\']',
selector: 'ExpressionStatement > CallExpression > ' +
'MemberExpression[object.name=\'suite\'][property.name=\'only\']',
message: 'Remove suite.only.',
},
],
@@ -245,6 +250,14 @@ module.exports = {
security: 'readonly',
},
overrides: [
{
files: ['.eslintrc.js', '.eslintrc-bazel.js'],
env: {
browser: false,
es6: true,
node: true,
},
},
{
// .js-only rules
files: ['**/*.js'],
@@ -273,7 +286,10 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'error',
// The following rules is required to match internal google rules
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
'@typescript-eslint/no-unused-vars': [
'error',
{argsIgnorePattern: '^_'},
],
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features/node-builtins.md
'node/no-unsupported-features/node-builtins': 'off',
// Disable no-invalid-this for ts files, because it incorrectly reports
@@ -324,7 +340,6 @@ module.exports = {
expect: 'readonly',
fixture: 'readonly',
flush: 'readonly',
flushAsynchronousOperations: 'readonly',
setup: 'readonly',
sinon: 'readonly',
stub: 'readonly',

View File

@@ -360,13 +360,6 @@ suite('gr-change-metadata tests', () => {
);
});
test('_getNonOwnerRole null for uploader with no current rev', () => {
delete change!.current_revision;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.UPLOADER)
);
});
test('_computeShowRoleClass show uploader', () => {
assert.equal(
element._computeShowRoleClass(change, element._CHANGE_ROLE.UPLOADER),
@@ -407,26 +400,12 @@ suite('gr-change-metadata tests', () => {
);
});
test('_getNonOwnerRole null for committer with no current rev', () => {
delete change!.current_revision;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.COMMITTER)
);
});
test('_getNonOwnerRole null for committer with no commit', () => {
delete change!.revisions.rev1.commit;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.COMMITTER)
);
});
test('_getNonOwnerRole null for committer with no committer', () => {
delete change!.revisions.rev1.commit!.committer;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.COMMITTER)
);
});
});
suite('role=author', () => {
@@ -445,26 +424,12 @@ suite('gr-change-metadata tests', () => {
);
});
test('_getNonOwnerRole null for author with no current rev', () => {
delete change!.current_revision;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.AUTHOR)
);
});
test('_getNonOwnerRole null for author with no commit', () => {
delete change!.revisions.rev1.commit;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.AUTHOR)
);
});
test('_getNonOwnerRole null for author with no author', () => {
delete change!.revisions.rev1.commit!.author;
assert.isNotOk(
element._getNonOwnerRole(change, element._CHANGE_ROLE.AUTHOR)
);
});
});
});
@@ -609,7 +574,6 @@ suite('gr-change-metadata tests', () => {
element.revision = undefined;
assert.equal(element._currentParents[0].commit, '111');
element.change = createParsedChange();
delete element.change.current_revision;
assert.deepEqual(element._currentParents, []);
});

View File

@@ -121,7 +121,7 @@ suite('gr-download-dialog', () => {
});
test('anchors use download attribute', () => {
const anchors = Array.from(element.root?.querySelectorAll('a')!);
const anchors = Array.from(element.root!.querySelectorAll('a'));
assert.isTrue(!anchors.some(a => !a.hasAttribute('download')));
});

View File

@@ -731,7 +731,7 @@ suite('gr-comment tests', () => {
path: SpecialFilePath.PATCHSET_LEVEL_COMMENTS, line: undefined,
range: undefined};
element.comment = comment;
flushAsynchronousOperations();
flush();
MockInteractions.tap(element.shadowRoot
.querySelector('.edit'));
assert.isTrue(element.editing);

View File

@@ -29,12 +29,6 @@ import {customElement, property, observe} from '@polymer/decorators';
import {IronDropdownElement} from '@polymer/iron-dropdown/iron-dropdown';
import {Timestamp} from '../../../types/common';
/**
* fired when the selected value of the dropdown changes
*
* @event {change}
*/
/**
* Requred values are text and value. mobileText and triggerText will
* fall back to text if not provided.

View File

@@ -17,6 +17,7 @@
import {AccountInfo, ChangeInfo} from '../types/common';
import {isServiceUser} from './account-util';
import {hasOwnProperty} from './common-util';
// You would typically use a ServerInfo here, but this utility does not care
// about all the other parameters in that object.
@@ -46,7 +47,8 @@ export function hasAttention(
return (
isAttentionSetEnabled(config) &&
canHaveAttention(account) &&
!!change?.attention_set?.hasOwnProperty(account!._account_id!)
!!change?.attention_set &&
hasOwnProperty(change?.attention_set, account!._account_id!)
);
}