Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mkszepp opened this issue May 22, 2024 · 4 comments · Fixed by #2151
Closed

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

mkszepp opened this issue May 22, 2024 · 4 comments · Fixed by #2151
Labels

Comments

@mkszepp
Copy link
Contributor

mkszepp commented May 22, 2024

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:

  • eslint-plugin-ember: 12.1.1 (also tested with 12.0.2)
  • Ember: 5.8
  • Ember cli: 5.8.1
@mkszepp mkszepp changed the title ember/no-runloop brings false positive error with functionname hasOwnProperty ember/no-runloop brings false positive error with function name hasOwnProperty May 22, 2024
@basz
Copy link

basz commented May 26, 2024

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
Copy link
Contributor Author

mkszepp commented May 27, 2024

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
Copy link

basz commented Jun 4, 2024

@mkszepp did you find a work around?

@mkszepp
Copy link
Contributor Author

mkszepp commented Jun 4, 2024

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

@bmish bmish added the bug label Jun 15, 2024
@ef4 ef4 closed this as completed in #2151 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants