How to use the eslint.Linter function in eslint

To help you get started, we’ve selected a few eslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / no-require-absolute-path / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;

var code = 'var stdlib = require( \'/path/to/stdlib/\' );';

linter.defineRule( 'no-require-absolute-path', rule );

result = linter.verify( code, {
	'rules': {
		'no-require-absolute-path': 'error'
	}
});
console.log( result );
/* =>
	[
		{
			'ruleId': 'no-require-absolute-path',
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / new-cap-regexp / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;

var code = 'var re = RegExp( \'ab+c\', \'i\' );';

linter.defineRule( 'new-cap-regexp', rule );

result = linter.verify( code, {
	'rules': {
		'new-cap-regexp': 'error'
	}
});
console.log( result );
/* =>
	[
		{
			'ruleId': 'new-cap-regexp',
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / jsdoc-no-paragraph-content-indent / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;
var code;

// Generate our source code:
code = [
	'/**',
	'* Beep boop.',
	'*',
	'* ## Beep',
	'*',
	'*    boop',
	'*',
	'* ## Beep',
	'*',
	'*  beep',
	'*',
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / jsdoc-tag-names / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;
var code;

code = [
	'/**',
	'* Squares a number.',
	'* ',
	'* @params {number} x - input number',
	'* @returns {number} x squared',
	'*',
	'* @examples',
	'* var y = square( 2.0 );',
	'* // returns 4.0',
	'*/',
	'function square( x ) {',
	'  return x*x;',
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / jsdoc-no-consecutive-blank-lines / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;
var code;

// Generate our source code:
code = [
	'/**',
	'* Beep boop.',
	'*',
	'* ## Beep',
	'*',
	'*',
	'* boop',
	'*',
	'* @param {string} str - input value',
	'* @returns {string} output value',
	'*',
github ChromeDevTools / devtools-frontend / scripts / migrate_test / format.js View on Github external
return char + '@@END_TEST_FUNCTION@@';
                                    }
                                    return char;
                                  })
                                  .join('');
                            }

                            return line;
                          })
                          .join('\n');

  newTestScript =
      escapedReplace(newTestScript, /@@START_TEST_FUNCTION@@[\S\s]*@@END_TEST_FUNCTION@@/, TEST_FUNCTION_SENTINEL);
  htmlContents = escapedReplace(htmlContents, testScript, newTestScript);

  let linter = new Linter();
  let result = linter.verifyAndFix(recast.print(functionNode).code, {
    envs: ['browser'],
    useEslintrc: false,
    parserOptions: {
      ecmaVersion: 8,
    },
    rules: {
      semi: 2,
    }
  });
  if (result.messages.length) {
    console.log('Issue with eslint', result.messages, 'for file: ', filePath);
    process.exit(1);
  }
  fs.writeFileSync(TEMP_JS_FILE, result.output);
  const formattedTestcode = shellOutput(`clang-format ${TEMP_JS_FILE} --style=FILE`);
github mysticatea / eslint-utils / test / get-innermost-scope.js View on Github external
it(`should return the innermost scope (${++i})`, () => {
            const linter = new eslint.Linter()

            let actualScope = null
            let expectedScope = null
            linter.defineRule("test", context => ({
                Program(node) {
                    const scope = context.getScope()
                    actualScope = getInnermostScope(scope, selectNode(node))
                    expectedScope = selectScope(scope)
                },
            }))
            linter.verify(code, {
                parserOptions: Object.assign(
                    { ecmaVersion: 2018 },
                    parserOptions
                ),
                rules: { test: "error" },
github AugustArchive / Maika / old / plugins / utility.js View on Github external
async run(client, ctx) {
                if (!ctx.args[0])
                    return ctx.send(`${client.emojis.ERROR} **|** Missing \`
github SharifPoetra / yumeko / handle / linter.js View on Github external
const linter = new (require("eslint").Linter)();
const { RichEmbed } = require("discord.js");
const bmsg = require("../assets/json/bad-message.json");
const no = require("../assets/json/nodetect-js.json");

module.exports = async msg => {
  if (no.includes(msg.guild.id)) return undefined;
  const input = msg.content.match(/```(js)?(.|\s)+```/gi)[0].replace(/```(js|javascript)?|```/gi, "").trim();
  const code = /\bawait\b/i.test(input) ? `(async function(){ \n${input}\n})()` : input;
  const errors = linter.verify(code, require("../assets/json/eslint-default.json"));
  if (errors.length < 1) return msg.react("✅");
  await msg.react("❌");
  msg.react("🔎");
  const errs = [];
  for (const e of errors) {
    errs.push(`- [${e.line}:${e.column}] ${e.message}`);
  }
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / eslint / rules / no-dynamic-exports / examples / index.js View on Github external
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var result;
var code;

code = [
	'module.exports = fun();',
	'',
	'function fun() {',
	'  return 3.14;',
	'}'
].join( '\n' );

linter.defineRule( 'no-dynamic-exports', rule );

result = linter.verify( code, {
	'rules': {
		'no-dynamic-exports': 'error'