Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substitute bitwise operation in ESLint

I'm trying to apply this code: How to get X Y Z coordinates of tile by click on Leaflet map - which contains bitwise operator "<<". In the environment that I'm running it on (NodeJS, ExpressJS, AngularJS), codes are checked by ESLint upon compiling it but I need the solution given on the link. I get this error on compilation .

Unexpected use of '<<' no-bitwise

According to this link: http://eslint.org/docs/rules/no-bitwise - ESLint disallows bitwise operators. Is there any way to bypass this rule or if not, provide an alternate calculation that produces similar results to bitwise operation '<<'?

I hope my question is clear, thanks.

like image 553
The Bassman Avatar asked Aug 18 '15 10:08

The Bassman


People also ask

How do you bypass ESLint?

To turn off ESLint in the whole file, you can add /* eslint-disable */ in the first line of that file.

How do you set rules in ESLint?

ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: "off" or 0 - turn the rule off.

How do I disable ESLint on next line?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

How many ESLint rules are there?

Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them). As such, any new rules must be deemed of high importance to be considered for inclusion in ESLint.


2 Answers

You need to add the comment //eslint-disable-line no-bitwise on the line you'd like for es-lint to ignore

e.g.

var x = 5 << 5; //eslint-disable-line no-bitwise
like image 182
Yuri Zarubin Avatar answered Oct 03 '22 16:10

Yuri Zarubin


For power of two you can use Math.pow

const scale = Math.pow( 2, zoom );
like image 32
Anton Duzenko Avatar answered Oct 03 '22 17:10

Anton Duzenko