New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-camelcase-ohm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-camelcase-ohm - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/camelcase-ohm.js

45

index.js
'use strict';
var camelcase = require('./third_party/camelcase');
// Checks whether the given node is considered an error by the camelcase rule.
function checkCamelCase(idNode) {
var reported = false;
var fakeContext = {
report: function() { reported = true; },
options: []
};
camelcase(fakeContext).Identifier(idNode); // eslint-disable-line new-cap
return !reported;
}
// Reports an AST node as a rule violation.
function report(context, node) {
context.report(node, "Identifier '{{name}}' is not camel case.", {name: node.name});
}
// Returns true if `name` appears to be the name of a semantic action.
// The idiomatic style in Ohm is `RuleName_caseName`.
function checkSemanticActionName(node) {
var name = node.name;
var underscoreIdx = name.indexOf('_');
// The underscore should not appear on the ends,
// case names should begin with a lowercase letter,
// and there should be only one underscore in the name.
if ((underscoreIdx > 0 && underscoreIdx < (name.length - 1)) &&
name[underscoreIdx + 1] === name[underscoreIdx + 1].toLowerCase() &&
name.indexOf('_', underscoreIdx + 1) === -1) {
return true;
module.exports = {
rules: {
'camelcase-ohm': require('./lib/camelcase-ohm')
}
return false;
}
module.exports = function(context) {
return {
Identifier: function(node) {
if (!checkCamelCase(node) && !checkSemanticActionName(node)) {
report(context, node);
}
}
};
};
{
"name": "eslint-plugin-camelcase-ohm",
"description": "An ESLint plugin that extends the built-in camelcase rule to allow underscores in semantic action names.",
"version": "0.1.0",
"version": "0.2.0",
"author": "Patrick Dubroy <pdubroy@gmail.com> (http://dubroy.com)",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -11,2 +11,4 @@ # eslint-plugin-camelcase-ohm

- Install this package as a dev dependency, e.g. `npm install eslint-plugin-camelcase-ohm`.
- Ensure the plugin is loaded, e.g. by adding the following to your `.eslintrc` file:

@@ -16,3 +18,3 @@

"plugins": [
"camelcase-ohm"
"eslint-plugin-camelcase-ohm"
]

@@ -25,3 +27,3 @@ ```

"rules": {
"camelcase-ohm/main": 2
"camelcase-ohm/camelcase-ohm": 2
}

@@ -28,0 +30,0 @@ ```

'use strict';
var rule = require('..');
var rule = require('../lib/camelcase-ohm');
var RuleTester = require('eslint').RuleTester;

@@ -5,0 +5,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc