Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*
* 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',
*
* 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',
*
* 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',
'*',
*
* 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;',
*
* 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',
'*',
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`);
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" },
async run(client, ctx) {
if (!ctx.args[0])
return ctx.send(`${client.emojis.ERROR} **|** Missing \`
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}`);
}
*
* 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'