Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created February 28, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retorquere/5144bbe3da1db27de445b5474282ef36 to your computer and use it in GitHub Desktop.
Save retorquere/5144bbe3da1db27de445b5474282ef36 to your computer and use it in GitHub Desktop.
	'debug': function (context) {
		return {
			Program: function (node) {
				console.log('debug active');
				context.report({
              node,
							message: 'debug active',
							loc: { start: { line: 1, column: 1 } },
				});
			}
		}
	},

  ...
  
	// this is a very simplistic rule to find 'unnecesary use of indexOf' until I find a better eslint plugin that does this
	'prefer-index-of': function (context) {
		return {
			Program: function (node) {
				let lineno = 0;
				let m;
				for (const line of context.getSourceCode().getText().split('\n')) { // eslint-disable-line newline-per-chained-call
					lineno += 1;

					if (m = line.match(/\.indexOf(.*) *(=+ *-1|!=+ *-1|> *-1|>= *0|< *0)/)) {
						context.report({
							node,
							message: "Unnecessary '.indexOf()', use '.includes()' instead",
							loc: { start: { line: lineno, column: line.indexOf(m[0]) + 1 } },
						});
					}
				}
			}
		};
	},
@retorquere
Copy link
Author

retorquere commented Feb 28, 2019

/* eslint-disable */ const __eslint_zotero_translator_header = { 
  "translatorID": "60e55b65-08cb-4a8f-8a61-c36338ec8754",
  "label": "Access Medicine",
  "creator": "Jaret M. Karnuta",
  "target": "^https?://(0-)?(access(anesthesiology|cardiology|emergencymedicine|medicine|pediatrics|surgery)|neurology)\\.mhmedical\\.com",
  "minVersion": "3.0",
  "maxVersion": "",
  "priority": 100,
  "inRepository": true,
  "translatorType": 4,
  "browserSupport": "gcsibv",
  "lastUpdated": "2017-01-12 22:14:02"
}; /* eslint-disable */

// more code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment