ember-cli / eslint-plugin-ember

An ESLint plugin that provides set of rules for Ember applications based on commonly known good practices.
MIT License
257 stars 198 forks source link

`ember/no-runloop` brings false positive error with function name `hasOwnProperty` #2150

Closed mkszepp closed 1 week ago

mkszepp commented 1 month ago

After cleanup of all ember/runloops, i have removed the rule ember/no-runloop. Now i'm getting a false positive error.

Example:

import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class MyRoute extends Route {
  @service router;

  setupController(controller) {
    super.setupController(controller);

    hasOwnProperty();
  }
}

function hasOwnProperty() {
  return 'hello';
}

grafik

While the lint rules brings wrong errors, there is necessary to disable the rule, because there is not allowed to set hasOwnproperty in allowedList.

// not allowed - error "Value "hasOwnProperty" should be equal to one of the allowed values."
 'ember/no-runloop': [
      'error',
      {
        allowList: ['hasOwnProperty'],
      },
    ],

Version:

basz commented 1 month ago

i'm seeying a false positive too at line 34 using 12.1.1

const svg = await toString(data, options);
import { assert } from '@ember/debug';
import Service from '@ember/service';

import { toDataURL, toString } from 'qrcode';

import type { QRCodeToDataURLOptionsJpegWebp, QRCodeToDataURLOptionsOther, QRCodeToStringOptions } from 'qrcode';

export default class RendererService extends Service {
  async renderDataUrl(data: string, options: QRCodeToStringOptions | QRCodeToDataURLOptionsJpegWebp | QRCodeToDataURLOptionsOther = {}): Promise<string> {
    if (!data.length) {
      return '';
    }

    if (!options?.type) {
      options.type = 'image/png';
    }

    if (!options?.errorCorrectionLevel) {
      options.errorCorrectionLevel = 'L';
    }

    if (!options?.margin) {
      options.margin = 0;
    }

    assert(`Attribute 'type' must be one of 'image/png', 'svg', 'image/jpeg'`, ['image/png', 'svg', 'image/jpeg'].includes(options.type));
    assert(`Attribute 'data' must be string...`, 'string' === typeof data);
    assert(`Attribute 'errorCorrectionLevel' must be string`, 'string' === typeof options.errorCorrectionLevel);
    assert(`Attribute 'errorCorrectionLevel' must be one of 'L', 'M', 'Q' or 'H'`, ['L', 'M', 'Q', 'H'].includes(options.errorCorrectionLevel));
    //    assert(`Attribute 'quality' must be a number`, options?.rendererOpts?.quality !== undefined ? typeof options?.rendererOpts?.quality === 'number' : true);

    switch (options.type) {
      case 'svg': {
        const svg = await toString(data, options);
        const blob = new Blob([svg], { type: 'image/svg+xml' });

        return URL.createObjectURL(blob);
      }
      case 'image/png':
      case 'image/jpeg':
        return await toDataURL(data, options);
      default:
        throw new Error('Unsupported QR Type');
    }
  }
}

declare module '@ember/service' {
  interface Registry {
    'qr-renderer': RendererService;
  }
}
mkszepp commented 1 month ago

Looks like when a function is named like a Object.prototype property (https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) there is a false positive error...

hasOwnProperty()
isPrototypeOf()
propertyIsEnumerable()
toLocaleString()
toString()
valueOf()
constructor()
basz commented 3 weeks ago

@mkszepp did you find a work around?

mkszepp commented 3 weeks ago

@basz atm i have disabled... i have not really experience with eslint rules, but i have commitet a possible fix...