initial commit of actions

This commit is contained in:
Dominik Polakovics Polakovics 2026-01-31 18:56:04 +01:00
commit 949ece5785
44660 changed files with 12034344 additions and 0 deletions

View file

@ -0,0 +1,123 @@
/**
* @fileoverview Rule to ensure that filenames match the exports of the file
* @author Stefan Lau
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var path = require('path'),
camelCase = require('lodash.camelcase'),
upperFirst = require('lodash.upperfirst'),
parseFilename = require('../common/parseFilename'),
isIgnoredFilename = require('../common/isIgnoredFilename'),
getExportedName = require('../common/getExportedName'),
isIndexFile = require('../common/isIndexFile'),
transforms = {
kebab: require('lodash.kebabcase'),
snake: require('lodash.snakecase'),
camel: camelCase,
pascal: function (name) {
return upperFirst(camelCase(name));
}
},
transformNames = Object.keys(transforms),
transformSchema = { "enum": transformNames.concat([ null ]) };
function getStringToCheckAgainstExport(parsed, replacePattern) {
var dirArray = parsed.dir.split(path.sep);
var lastDirectory = dirArray[dirArray.length - 1];
if (isIndexFile(parsed)) {
return lastDirectory;
} else {
return replacePattern ? parsed.name.replace(replacePattern, '') : parsed.name;
}
}
function getTransformsFromOptions(option) {
var usedTransforms = (option && option.push) ? option : [ option ];
return usedTransforms.map(function (name) {
return transforms[name];
});
}
function transform(exportedName, transforms) {
return transforms.map(function (t) {
return t ? t(exportedName) : exportedName;
});
}
function anyMatch(expectedExport, transformedNames) {
return transformedNames.some(function (name) {
return name === expectedExport;
});
}
function getWhatToMatchMessage(transforms) {
if (transforms.length === 1 && !transforms[0]) {
return "the exported name";
}
if (transforms.length > 1) {
return "any of the exported and transformed names"
}
return "the exported and transformed name";
}
module.exports = function(context) {
return {
"Program": function (node) {
var transforms = getTransformsFromOptions(context.options[0]),
replacePattern = context.options[1] ? new RegExp(context.options[1]) : null,
filename = context.getFilename(),
absoluteFilename = path.resolve(filename),
parsed = parseFilename(absoluteFilename),
shouldIgnore = isIgnoredFilename(filename),
exportedName = getExportedName(node, context.options),
isExporting = Boolean(exportedName),
expectedExport = getStringToCheckAgainstExport(parsed, replacePattern),
transformedNames = transform(exportedName, transforms),
everythingIsIndex = exportedName === 'index' && parsed.name === 'index',
matchesExported = anyMatch(expectedExport, transformedNames) || everythingIsIndex,
reportIf = function (condition, messageForNormalFile, messageForIndexFile) {
var message = (!messageForIndexFile || !isIndexFile(parsed)) ? messageForNormalFile : messageForIndexFile;
if (condition) {
context.report(node, message, {
name: parsed.base,
expectedExport: expectedExport,
exportName: transformedNames.join("', '"),
extension: parsed.ext,
whatToMatch: getWhatToMatchMessage(transforms)
});
}
};
if (shouldIgnore) return;
reportIf(
isExporting && !matchesExported,
"Filename '{{expectedExport}}' must match {{whatToMatch}} '{{exportName}}'.",
"The directory '{{expectedExport}}' must be named '{{exportName}}', after the exported value of its index file."
);
}
}
};
module.exports.schema = [
{
oneOf: [
transformSchema,
{ type: "array", items: transformSchema, minItems: 1 }
]
},
{
type: [ "string", "null" ]
},
{
type: [ "boolean", "null" ]
}
];

View file

@ -0,0 +1,40 @@
/**
* @fileoverview Rule to ensure that filenames match a convention (default: camelCase)
* @author Stefan Lau
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
"use strict";
var path = require("path"),
parseFilename = require('../common/parseFilename'),
getExportedName = require('../common/getExportedName'),
isIgnoredFilename = require('../common/isIgnoredFilename');
module.exports = function(context) {
var defaultRegexp = /^([a-z0-9]+)([A-Z][a-z0-9]+)*$/g,
conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp,
ignoreExporting = context.options[1] ? context.options[1] : false;
return {
"Program": function(node) {
var filename = context.getFilename(),
absoluteFilename = path.resolve(filename),
parsed = parseFilename(absoluteFilename),
shouldIgnore = isIgnoredFilename(filename),
isExporting = Boolean(getExportedName(node)),
matchesRegex = conventionRegexp.test(parsed.name);
if (shouldIgnore) return;
if (ignoreExporting && isExporting) return;
if (!matchesRegex) {
context.report(node, "Filename '{{name}}' does not match the naming convention.", {
name: parsed.base
});
}
}
};
};

View file

@ -0,0 +1,32 @@
/**
* @fileoverview Rule to ensure that there exist no index files
* @author Stefan Lau
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var path = require('path'),
parseFilename = require('../common/parseFilename'),
isIgnoredFilename = require('../common/isIgnoredFilename'),
isIndexFile = require('../common/isIndexFile');
module.exports = function(context) {
return {
"Program": function(node) {
var filename = context.getFilename(),
absoluteFilename = path.resolve(filename),
parsed = parseFilename(absoluteFilename),
shouldIgnore = isIgnoredFilename(filename),
isIndex = isIndexFile(parsed);
if (shouldIgnore) return;
if (isIndex) {
context.report(node, "'index.js' files are not allowed.");
}
}
};
};