Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-canonical

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-canonical - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

dist/rules/exportSpecifierNewline.js

2

dist/configs/recommended.json

@@ -12,2 +12,3 @@ {

"rules": {
"canonical/export-specifier-newline": 1,
"canonical/filename-match-exported": 0,

@@ -24,2 +25,3 @@ "canonical/filename-match-regex": 0,

],
"canonical/import-specifier-newline": 1,
"canonical/no-restricted-strings": 0,

@@ -26,0 +28,0 @@ "canonical/no-use-extend-native": 2,

@@ -10,2 +10,4 @@ "use strict";

var _exportSpecifierNewline = _interopRequireDefault(require("./rules/exportSpecifierNewline"));
var _filenameMatchExported = _interopRequireDefault(require("./rules/filenameMatchExported"));

@@ -19,2 +21,4 @@

var _importSpecifierNewline = _interopRequireDefault(require("./rules/importSpecifierNewline"));
var _noRestrictedStrings = _interopRequireDefault(require("./rules/noRestrictedStrings"));

@@ -33,2 +37,3 @@

rules: {
'export-specifier-newline': _exportSpecifierNewline.default,
'filename-match-exported': _filenameMatchExported.default,

@@ -38,2 +43,3 @@ 'filename-match-regex': _filenameMatchRegex.default,

'id-match': _idMatch.default,
'import-specifier-newline': _importSpecifierNewline.default,
'no-restricted-strings': _noRestrictedStrings.default,

@@ -44,2 +50,3 @@ 'no-use-extend-native': _noUseExtendNative.default,

rulesConfig: {
'export-specifier-newline': 0,
'filename-match-exported': 0,

@@ -49,2 +56,3 @@ 'filename-match-regex': 0,

'id-match': 0,
'import-specifier-newline': 0,
'no-restricted-strings': 0,

@@ -51,0 +59,0 @@ 'no-use-extend-native': 0,

@@ -24,2 +24,3 @@ "use strict";

const create = context => {
// eslint-disable-next-line unicorn/no-unsafe-regex
const defaultRegexp = /^([\da-z]+)([A-Z][\da-z]+)*$/ug;

@@ -26,0 +27,0 @@ const conventionRegexp = context.options[0] ? new RegExp(context.options[0], 'u') : defaultRegexp;

38

dist/rules/idMatch.js

@@ -58,8 +58,8 @@ "use strict";

/**
* Checks if a string matches the provided pattern
*
* @param {string} name The string to check.
* @returns {boolean} if the string is a match
* @private
*/
* Checks if a string matches the provided pattern
*
* @param {string} name The string to check.
* @returns {boolean} if the string is a match
* @private
*/

@@ -70,9 +70,9 @@ function isInvalid(name) {

/**
* Verifies if we should report an error or not based on the effective
* parent node and the identifier name.
*
* @param {ASTNode} effectiveParent The effective parent node of the node to be reported
* @param {string} name The identifier name of the identifier node
* @returns {boolean} whether an error should be reported or not
*/
* Verifies if we should report an error or not based on the effective
* parent node and the identifier name.
*
* @param {ASTNode} effectiveParent The effective parent node of the node to be reported
* @param {string} name The identifier name of the identifier node
* @returns {boolean} whether an error should be reported or not
*/

@@ -84,8 +84,8 @@

/**
* Reports an AST node as a rule violation.
*
* @param {ASTNode} node The node to report.
* @returns {void}
* @private
*/
* Reports an AST node as a rule violation.
*
* @param {ASTNode} node The node to report.
* @returns {void}
* @private
*/

@@ -92,0 +92,0 @@

@@ -139,6 +139,6 @@ "use strict";

/**
* handles cases like {}[i][j]
* not enough information to identify type of variable in computed properties
* so ignore false positives by not performing any checks
*/
* handles cases like {}[i][j]
* not enough information to identify type of variable in computed properties
* so ignore false positives by not performing any checks
*/
return;

@@ -145,0 +145,0 @@ }

@@ -20,32 +20,32 @@ "use strict";

/**
* Gets the property name of a given node.
* The node can be a MemberExpression, a Property, or a MethodDefinition.
*
* If the name is dynamic, this returns `null`.
*
* For examples:
*
* a.b // => "b"
* a["b"] // => "b"
* a['b'] // => "b"
* a[`b`] // => "b"
* a[100] // => "100"
* a[b] // => null
* a["a" + "b"] // => null
* a[tag`b`] // => null
* a[`${b}`] // => null
*
* let a = {b: 1} // => "b"
* let a = {["b"]: 1} // => "b"
* let a = {['b']: 1} // => "b"
* let a = {[`b`]: 1} // => "b"
* let a = {[100]: 1} // => "100"
* let a = {[b]: 1} // => null
* let a = {["a" + "b"]: 1} // => null
* let a = {[tag`b`]: 1} // => null
* let a = {[`${b}`]: 1} // => null
*
* @param {ASTNode} node - The node to get.
* @returns {string|null} The property name if static. Otherwise, null.
*/
* Gets the property name of a given node.
* The node can be a MemberExpression, a Property, or a MethodDefinition.
*
* If the name is dynamic, this returns `null`.
*
* For examples:
*
* a.b // => "b"
* a["b"] // => "b"
* a['b'] // => "b"
* a[`b`] // => "b"
* a[100] // => "100"
* a[b] // => null
* a["a" + "b"] // => null
* a[tag`b`] // => null
* a[`${b}`] // => null
*
* let a = {b: 1} // => "b"
* let a = {["b"]: 1} // => "b"
* let a = {['b']: 1} // => "b"
* let a = {[`b`]: 1} // => "b"
* let a = {[100]: 1} // => "100"
* let a = {[b]: 1} // => null
* let a = {["a" + "b"]: 1} // => null
* let a = {[tag`b`]: 1} // => null
* let a = {[`${b}`]: 1} // => null
*
* @param {ASTNode} node - The node to get.
* @returns {string|null} The property name if static. Otherwise, null.
*/
const getStaticPropertyName = node => {

@@ -89,13 +89,13 @@ let prop;

/**
* Gets the property name of the given `Property` node.
*
* - If the property's key is an `Identifier` node, this returns the key's name
* whether it's a computed property or not.
* - If the property has a static name, this returns the static name.
* - Otherwise, this returns null.
*
* @param {ASTNode} node - The `Property` node to get.
* @returns {string|null} The property name or null.
* @private
*/
* Gets the property name of the given `Property` node.
*
* - If the property's key is an `Identifier` node, this returns the key's name
* whether it's a computed property or not.
* - If the property has a static name, this returns the static name.
* - Otherwise, this returns null.
*
* @param {ASTNode} node - The `Property` node to get.
* @returns {string|null} The property name or null.
* @private
*/

@@ -113,9 +113,9 @@

/**
* Functions which check that the given 2 names are in specific order.
*
* Postfix `I` is meant insensitive.
* Postfix `N` is meant natual.
*
* @private
*/
* Functions which check that the given 2 names are in specific order.
*
* Postfix `I` is meant insensitive.
* Postfix `N` is meant natual.
*
* @private
*/

@@ -122,0 +122,0 @@

@@ -7,16 +7,23 @@ {

},
"dependencies": {
"is-get-set-prop": "^1.0.0",
"is-js-type": "^2.0.0",
"is-obj-prop": "^1.0.0",
"is-proto-prop": "^2.0.0",
"natural-compare": "^1.4.0"
},
"description": "Canonical linting rules for ESLint.",
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.8",
"@babel/eslint-parser": "^7.15.8",
"@babel/node": "^7.15.8",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"@babel/preset-env": "^7.15.8",
"ajv": "^8.6.3",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.5",
"@babel/eslint-parser": "^7.16.5",
"@babel/node": "^7.16.5",
"@babel/plugin-transform-react-jsx": "^7.16.5",
"@babel/preset-env": "^7.16.5",
"ajv": "^8.8.2",
"babel-plugin-add-module-exports": "^1.0.4",
"eclint": "^2.8.1",
"eslint": "^8.1.0",
"eslint-config-canonical": "^32.10.1",
"eslint-plugin-eslint-plugin": "^4.0.2",
"eslint": "^8.5.0",
"eslint-config-canonical": "^32.46.1",
"eslint-plugin-eslint-plugin": "^4.1.0",
"gitdown": "^3.1.4",

@@ -29,3 +36,3 @@ "glob": "^7.2.0",

"rimraf": "^3.0.2",
"semantic-release": "^18.0.0"
"semantic-release": "^18.0.1"
},

@@ -44,3 +51,3 @@ "engines": {

"peerDependencies": {
"eslint": "^8.1.0"
"eslint": "^8.5.0"
},

@@ -61,10 +68,3 @@ "repository": {

},
"version": "2.1.0",
"dependencies": {
"is-get-set-prop": "^1.0.0",
"is-js-type": "^2.0.0",
"is-obj-prop": "^1.0.0",
"is-proto-prop": "^2.0.0",
"natural-compare": "^1.4.0"
}
"version": "2.2.0"
}

@@ -15,2 +15,3 @@ <a name="eslint-plugin-canonical"></a>

* [Rules](#eslint-plugin-canonical-rules)
* [`export-specifier-newline`](#eslint-plugin-canonical-rules-export-specifier-newline)
* [`filename-match-exported`](#eslint-plugin-canonical-rules-filename-match-exported)

@@ -20,2 +21,3 @@ * [`filename-match-regex`](#eslint-plugin-canonical-rules-filename-match-regex)

* [`id-match`](#eslint-plugin-canonical-rules-id-match)
* [`import-specifier-newline`](#eslint-plugin-canonical-rules-import-specifier-newline)
* [`no-restricted-strings`](#eslint-plugin-canonical-rules-no-restricted-strings)

@@ -106,7 +108,46 @@ * [`no-use-extend-native`](#eslint-plugin-canonical-rules-no-use-extend-native)

<a name="eslint-plugin-canonical-rules-export-specifier-newline"></a>
### <code>export-specifier-newline</code>
Forces every export specifier to be on a new line.
The following patterns are considered problems:
```js
const a = 1; const b = 2; const c = 3; export { a, b, c };
// Message: undefined
// Message: undefined
const a = 1; const b = 2; const c = 3; export { a, b, c, };
// Message: undefined
// Message: undefined
const a = 1; const b = 2; export { a as default, b }
// Message: undefined
```
The following patterns are not considered problems:
```js
export {
a,
b,
c
} from 'foo'
const a = 1; const b = 2; const c = 3; export {
a,
b,
c
};
export * from 'foo'
```
<a name="eslint-plugin-canonical-rules-filename-match-exported"></a>
### <code>filename-match-exported</code>
Match the file name against the default exported value in the module. Files that dont have a default export will
be ignored. The exports of `index.js` are matched against their parent directory.
Match the file name against the default exported value in the module. Files that don't have a default export will be ignored. The exports of `index.js` are matched against their parent directory.

@@ -141,7 +182,8 @@ ```js

Available transforms:
'[snake](https://www.npmjs.com/package/lodash.snakecase)',
'[kebab](https://www.npmjs.com/package/lodash.kebabcase)',
'[camel](https://www.npmjs.com/package/lodash.camelcase)', and
'pascal' (camel-cased with first letter in upper case).
* snake
* kebab
* camel
* pascal
For multiple transforms simply specify an array like this (null in this case stands for no transform):

@@ -153,5 +195,3 @@

If you prefer to use suffixes for your files (e.g. `Foo.react.js` for a React component file),
you can use a second configuration parameter. It allows you to remove parts of a filename matching a regex pattern
before transforming and matching against the export.
If you prefer to use suffixes for your files (e.g. `Foo.react.js` for a React component file), you can use a second configuration parameter. It allows you to remove parts of a filename matching a regex pattern before transforming and matching against the export.

@@ -233,6 +273,2 @@ ```json

// Options: [[null]]
export default variableName;
// Message: Filename 'VariableName' must match the exported name 'variableName'.
// Options: [["pascal","snake"]]

@@ -730,2 +766,29 @@ export default variableName;

<a name="eslint-plugin-canonical-rules-import-specifier-newline"></a>
### <code>import-specifier-newline</code>
Forces every import specifier to be on a new line.
The following patterns are considered problems:
```js
import {a, b} from 'foo';
// Message: undefined
import a, {b, c} from 'foo';
// Message: undefined
```
The following patterns are not considered problems:
```js
import {a,
b} from 'foo'
import a, {b,
c} from 'foo'
```
<a name="eslint-plugin-canonical-rules-no-restricted-strings"></a>

@@ -732,0 +795,0 @@ ### <code>no-restricted-strings</code>

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