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

@scandipwa/eslint-plugin-scandipwa-guidelines

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scandipwa/eslint-plugin-scandipwa-guidelines - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

lib/rules/export-level-one.js

6

lib/rules/derived-class-names.js
/**
* @fileoverview Class name must match the name of the file it is declared in.
* @author Alfreds Genkins
* @author Jegors Batovs
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
function capitalize(word) {

@@ -11,0 +7,0 @@ return word.charAt(0).toUpperCase() + word.slice(1);

/**
* @fileoverview File structure must comply to the strict guidelines of ScandiPWA
* @author Alfreds Genkins
* @author Jegors Batovs
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/* eslint-disable max-len */

@@ -49,3 +45,3 @@ /* eslint-disable no-magic-numbers */

case 'route':
if (!(['component', 'container', 'style'].includes(postfix))) {
if (!(['component', 'container', 'style', 'config', 'unstated'].includes(postfix))) {
return exploded[0];

@@ -52,0 +48,0 @@ }

/**
* @fileoverview Non-extensible components are not allowed.
* @author Alfreds Genkins
* @author Jegors Batovs
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
function keepOrDeleteNode(context, node) {

@@ -66,36 +62,4 @@ const { name } = node.specifiers[0].local;

}
},
VariableDeclaration(node) {
const { parent, declarations: [{ id: { loc, name } }] } = node;
const { type } = parent || {};
if (parent.type !== 'Program') {
return;
}
if (type !== 'ExportNamedDeclaration') {
context.report({
loc,
message: `Variable ${name} must be exported (as non default) to allow proper extension.`,
fix: fixer => fixer.insertTextBefore(node, 'export ')
});
}
},
ClassDeclaration(node) {
const { parent, id: { loc, name } } = node;
const { type } = parent || {};
if (type !== 'ExportNamedDeclaration') {
context.report({
loc,
message: `Class ${name} must be exported (as non default) to allow proper extension.`,
fix: fixer => {
if (parent.type === 'Program') {
fixer.insertTextBefore(node, 'export ')
}
}
});
}
}
}
})
};
/**
* @fileoverview There should be only one class per file
* @author Alfreds Genkins
* @author Jegors Batovs
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
// eslint-disable-next-line fp/no-let, scandipwa-extensibility/no-non-extensible-components

@@ -11,0 +7,0 @@ let classCount;

/**
* @fileoverview All components should be extensible.
* @author Alfreds Genkins
* @author Jegors Batovs
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {

@@ -24,3 +20,3 @@ meta: {

const { superClass } = node;
const { name, loc: superClassLoc } = superClass || {};
const { name } = superClass || {};
const { id: declaration } = node;

@@ -39,3 +35,3 @@ const { loc } = declaration;

context.report({
superClassLoc,
loc,
message: `${name} is not allowed. Use 'Extensible${name}' instead`,

@@ -42,0 +38,0 @@ fix: fixer => fixer.replaceText(superClass, `Extensible${name}`)

/**
* @fileoverview Wrap default export classes in middleware function
* @author Alfreds Genkins
* @author Jegors Batovs
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
function checkCall(context, callee) {
const { type, name } = callee;
if (type === 'Identifier' && name === 'middleware') {
return true;
}
if (type === 'CallExpression' || type === 'NewExpression') {
const { callee: nextCallee, arguments: args } = callee;
if (checkCall(context, nextCallee)) {
return true;
}
// eslint-disable-next-line fp/no-loops, no-restricted-syntax
for (const arg of args) {
if (checkCall(context, arg)) {
return true;
}
}
}
return false;
}
let classExists = false;
module.exports = {

@@ -18,28 +38,50 @@ meta: {

},
fixable: null, // or "code" or "whitespace"
schema: [
// fill in your schema
]
fixable: 'code',
},
create: function(context) {
create: context => ({
Program() {
classExists = false;
},
ClassDeclaration() {
classExists = true;
},
ExportDefaultDeclaration(node) {
if (!classExists && node.declaration.type !== 'ClassDeclaration') {
return;
}
// variables should be defined here
if (node.declaration.type === 'ClassDeclaration') {
context.report({
node,
message: 'Use middleware function when exporting extensible class. Declare it separately.'
});
}
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
if (node.declaration.type === 'Identifier') {
context.report({
node,
message: 'Use middleware function when exporting class',
fix: (fixer) => {
const { declaration } = node;
// any helper functions should go here or else delete this section
return [
fixer.insertTextBefore(declaration, 'middleware('),
fixer.insertTextAfter(declaration, ", 'NAMESPACE')")
];
}
});
}
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
// give me methods
};
}
if (node.declaration.type === 'CallExpression' || node.declaration.type === 'NewExpression') {
const { declaration } = node;
if (!checkCall(context, declaration)) {
context.report({
node,
message: 'Use middleware function when wrapping exporting value in other functions'
});
}
}
}
})
};
{
"name": "@scandipwa/eslint-plugin-scandipwa-guidelines",
"version": "1.2.1",
"version": "1.3.0",
"description": "Eslint rules for ScandiPWA",

@@ -5,0 +5,0 @@ "keywords": [

@@ -6,3 +6,3 @@ /* eslint-disable import/no-extraneous-dependencies */

* @fileoverview Class name must match the name of the file it is declared in.
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -9,0 +9,0 @@

/**
* @fileoverview File structure must comply to the strict guidelines of ScandiPWA
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -5,0 +5,0 @@ "use strict";

/**
* @fileoverview Non-extensible components are not allowed.
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -5,0 +5,0 @@ "use strict";

/**
* @fileoverview There should be only one class per file
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -5,0 +5,0 @@ "use strict";

/**
* @fileoverview All components should be extensible.
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -5,0 +5,0 @@ "use strict";

/**
* @fileoverview Wrap default export classes in middleware function
* @author Alfreds Genkins
* @author Jegors Batovs
*/

@@ -5,0 +5,0 @@ "use strict";

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