Added eslint rule for file naming convention

As discussed with the product team we want to enforce kebab-case file names for
all files, with the exception of files which export a single class, in which
case they should be PascalCase and reflect the class which they export.

This will help find classes faster, and should push better naming for them too.

Some files and packages have been excluded from this linting, specifically when
a library or framework depends on the naming of a file for the functionality
e.g. Ember, knex-migrator, adapter-manager
This commit is contained in:
Fabien "egg" O'Carroll 2023-05-02 16:43:47 -04:00 committed by Fabien 'egg' O'Carroll
parent 8a08cf3628
commit 104f84f252
295 changed files with 944 additions and 439 deletions

View File

@ -1 +1 @@
module.exports = require('./lib/adapter-cache-memory-ttl');
module.exports = require('./lib/AdapterCacheMemoryTTL');

View File

@ -8,7 +8,7 @@ const Base = require('@tryghost/adapter-base-cache');
* - it supports time-to-live (TTL)
* - it supports a max number of items
*/
class MemoryTTL extends Base {
class AdapterCacheMemoryTTL extends Base {
#cache;
/**
@ -51,4 +51,4 @@ class MemoryTTL extends Base {
}
}
module.exports = MemoryTTL;
module.exports = AdapterCacheMemoryTTL;

View File

@ -1 +1 @@
module.exports = require('./lib/adapter-cache-redis');
module.exports = require('./lib/AdapterCacheRedis');

View File

@ -4,7 +4,7 @@ const cacheManager = require('cache-manager');
const redisStore = require('cache-manager-ioredis');
const calculateSlot = require('cluster-key-slot');
class Redis extends BaseCacheAdapter {
class AdapterCacheRedis extends BaseCacheAdapter {
/**
*
* @param {Object} config
@ -155,4 +155,4 @@ class Redis extends BaseCacheAdapter {
}
}
module.exports = Redis;
module.exports = AdapterCacheRedis;

View File

@ -27,6 +27,8 @@ module.exports = {
'plugin:ghost/ember'
],
rules: {
'ghost/filenames/match-exported-class': ['off'],
'ghost/filenames/match-regex': ['off'],
'no-shadow': ['error'],
// TODO: migrate away from accessing controller in routes

View File

@ -79,7 +79,7 @@
"chalk": "4.1.2",
"chokidar": "3.5.3",
"copy-webpack-plugin": "11.0.0",
"eslint-plugin-ghost": "2.16.0",
"eslint-plugin-ghost": "3.0.0",
"minimist": "1.2.8",
"nock": "13.3.0",
"ora": "5.4.1",

View File

@ -8,7 +8,7 @@ module.exports = {
},
get Frame() {
return require('./frame');
return require('./Frame');
},
get pipeline() {

View File

@ -1,7 +1,7 @@
const url = require('url');
const debug = require('@tryghost/debug')('http');
const Frame = require('./frame');
const Frame = require('./Frame');
const headers = require('./headers');
/**

View File

@ -3,7 +3,7 @@ const _ = require('lodash');
const errors = require('@tryghost/errors');
const {sequence} = require('@tryghost/promise');
const Frame = require('./frame');
const Frame = require('./Frame');
const serializers = require('./serializers');
const validators = require('./validators');

View File

@ -1 +1 @@
module.exports = require('./lib/api-version-compatibility-service');
module.exports = require('./lib/APIVersionCompatibilityService');

View File

@ -6,10 +6,10 @@
"text-summary",
"cobertura"
],
"statements": 59,
"statements": 58.8,
"branches": 84,
"functions": 50,
"lines": 59,
"lines": 58.8,
"include": [
"core/{*.js,frontend,server,shared}"
],

View File

@ -13,7 +13,9 @@ module.exports = {
// @TODO: remove this rule once it's turned into "error" in the base plugin
'no-shadow': 'error',
'no-var': 'error',
'one-var': ['error', 'never']
'one-var': ['error', 'never'],
'ghost/ghost-custom/ghost-error-usage': [1],
'ghost/ghost-custom/no-native-error': [1]
},
overrides: [
{
@ -76,6 +78,12 @@ module.exports = {
]]
}
},
{
files: ['core/frontend/helpers/**', 'core/frontend/apps/*/lib/helpers/**'],
rules: {
'ghost/filenames/match-regex': ['off', '^[a-z0-9-.]$', null, true]
}
},
/**
* @TODO: enable these soon
*/

View File

@ -1,3 +1,4 @@
/* eslint-disable ghost/filenames/match-regex */
const config = require('./core/shared/config');
const ghostVersion = require('@tryghost/version');

View File

@ -64,7 +64,7 @@ function notifyServerReady(error) {
* @param {object} options.config
*/
async function initDatabase({config}) {
const DatabaseStateManager = require('./server/data/db/state-manager');
const DatabaseStateManager = require('./server/data/db/DatabaseStateManager');
const dbStateManager = new DatabaseStateManager({knexMigratorFilePath: config.get('paths:appRoot')});
await dbStateManager.makeReady();
@ -476,7 +476,7 @@ async function bootGhost({backend = true, frontend = true, server = true} = {})
const rootApp = require('./app')();
if (server) {
const GhostServer = require('./server/ghost-server');
const GhostServer = require('./server/GhostServer');
ghostServer = new GhostServer({url: config.getSiteUrl(), env: config.get('env'), serverConfig: config.get('server')});
await ghostServer.start(rootApp);
bootLogger.log('server started');

View File

@ -1,4 +1,4 @@
const AdminAuthAssetsService = require('./service');
const AdminAuthAssetsService = require('./AdminAuthAssetsService');
let adminAuthAssets = new AdminAuthAssetsService();
module.exports = adminAuthAssets;

View File

@ -1,4 +1,4 @@
const CardAssetService = require('./service');
const CardAssetService = require('./CardAssetService');
let cardAssetService = new CardAssetService();
module.exports = cardAssetService;

View File

@ -1,4 +1,4 @@
const CommentCountsAssetsService = require('./service');
const CommentCountsAssetsService = require('./CommentCountsAssetsService');
let commentCountsAssets = new CommentCountsAssetsService();
module.exports = commentCountsAssets;

View File

@ -1,4 +1,4 @@
const MemberAttributionAssetsService = require('./service');
const MemberAttributionAssetsService = require('./MemberAttributionAssetsService');
const memberAttributionAssets = new MemberAttributionAssetsService();
module.exports = memberAttributionAssets;

View File

@ -1,5 +1,5 @@
const registry = require('./registry');
const RouterManager = require('./router-manager');
const RouterManager = require('./RouterManager');
const routerManager = new RouterManager({registry});
module.exports = {

View File

@ -1,5 +1,5 @@
const _ = require('lodash');
const BaseMapGenerator = require('./base-generator');
const BaseMapGenerator = require('./BaseSiteMapGenerator');
class PageMapGenerator extends BaseMapGenerator {
constructor(opts) {

View File

@ -1,5 +1,5 @@
const _ = require('lodash');
const BaseMapGenerator = require('./base-generator');
const BaseMapGenerator = require('./BaseSiteMapGenerator');
class PostMapGenerator extends BaseMapGenerator {
constructor(opts) {

View File

@ -1,10 +1,10 @@
const DomainEvents = require('@tryghost/domain-events');
const {URLResourceUpdatedEvent} = require('@tryghost/dynamic-routing-events');
const IndexMapGenerator = require('./index-generator');
const PagesMapGenerator = require('./page-generator');
const PostsMapGenerator = require('./post-generator');
const UsersMapGenerator = require('./user-generator');
const TagsMapGenerator = require('./tag-generator');
const IndexMapGenerator = require('./SiteMapIndexGenerator');
const PagesMapGenerator = require('./PageMapGenerator');
const PostsMapGenerator = require('./PostMapGenerator');
const UsersMapGenerator = require('./UserMapGenerator');
const TagsMapGenerator = require('./TagsMapGenerator');
// This uses events from the routing service and the URL service
const events = require('../../../server/lib/common/events');

View File

@ -1,5 +1,5 @@
const _ = require('lodash');
const BaseMapGenerator = require('./base-generator');
const BaseMapGenerator = require('./BaseSiteMapGenerator');
class TagsMapGenerator extends BaseMapGenerator {
constructor(opts) {

View File

@ -1,6 +1,6 @@
const _ = require('lodash');
const validator = require('@tryghost/validator');
const BaseMapGenerator = require('./base-generator');
const BaseMapGenerator = require('./BaseSiteMapGenerator');
class UserMapGenerator extends BaseMapGenerator {
constructor(opts) {

View File

@ -1,5 +1,5 @@
const config = require('../../../shared/config');
const Manager = require('./manager');
const Manager = require('./SiteMapManager');
const manager = new Manager();
// Responsible for handling requests for sitemap files

View File

@ -1,6 +1,6 @@
const errors = require('@tryghost/errors');
const logging = require('@tryghost/logging');
const I18n = require('./i18n');
const I18n = require('./I18n');
class ThemeI18n extends I18n {
/**

View File

@ -1,6 +1,6 @@
const config = require('../../../../shared/config');
const ThemeI18n = require('./theme-i18n');
const ThemeI18n = require('./ThemeI18n');
module.exports = new ThemeI18n({basePath: config.getContentPath('themes')});
module.exports.ThemeI18n = ThemeI18n;

View File

@ -3,7 +3,7 @@ const routing = require('../services/routing');
/**
*
* @param {import('../services/routing/router-manager').RouterConfig} routerConfig
* @param {import('../services/routing/RouterManager').RouterConfig} routerConfig
* @returns {import('express').Router}
*/
module.exports = function siteRoutes(routerConfig) {

View File

@ -33,7 +33,7 @@ function SiteRouter(req, res, next) {
/**
*
* @param {import('../services/routing/router-manager').RouterConfig} routerConfig
* @param {import('../services/routing/RouterManager').RouterConfig} routerConfig
* @returns {import('express').Application}
*/
module.exports = function setupSiteApp(routerConfig) {
@ -172,7 +172,7 @@ module.exports = function setupSiteApp(routerConfig) {
/**
* see https://github.com/expressjs/express/issues/2596
* @param {import('../services/routing/router-manager').RouterConfig} routerConfig
* @param {import('../services/routing/RouterManager').RouterConfig} routerConfig
*/
module.exports.reload = (routerConfig) => {
debug('reloading');

View File

@ -1,3 +1,4 @@
/* eslint-disable ghost/filenames/match-regex */
const RedisCache = require('@tryghost/adapter-cache-redis');
module.exports = RedisCache;

View File

@ -1,7 +1,7 @@
const Promise = require('bluebird');
const events = require('../../../lib/common/events');
const localUtils = require('../utils');
const PostScheduler = require('./post-scheduler');
const PostScheduler = require('./PostScheduler');
const getSchedulerIntegration = require('./scheduler-intergation');
/**

View File

@ -1,7 +1,7 @@
const util = require('util');
const moment = require('moment');
const debug = require('@tryghost/debug')('scheduling-default');
const SchedulingBase = require('./SchedulingBase');
const SchedulingBase = require('./scheduling-base');
const logging = require('@tryghost/logging');
const errors = require('@tryghost/errors');
const request = require('@tryghost/request');

View File

@ -1,4 +1,4 @@
const Base = require('./Base');
const Base = require('./SSOBase');
module.exports = class DefaultSSOAdapter extends Base {
constructor() {

View File

@ -10,7 +10,7 @@ const messages = {
cannotRead: 'Could not read media file: {file}'
};
class LocalMediaStore extends LocalStorageBase {
class LocalMediaStorage extends LocalStorageBase {
constructor() {
super({
storagePath: config.getContentPath('media'),
@ -21,4 +21,4 @@ class LocalMediaStore extends LocalStorageBase {
}
}
module.exports = LocalMediaStore;
module.exports = LocalMediaStorage;

View File

@ -10,7 +10,7 @@ const invitations = require('../../services/invitations');
const dbBackup = require('../../data/db/backup');
const apiMail = require('./index').mail;
const apiSettings = require('./index').settings;
const UsersService = require('../../services/users');
const UsersService = require('../../services/Users');
const userService = new UsersService({dbBackup, models, auth, apiMail, apiSettings});
const {deleteAllSessions} = require('../../services/auth/session');

View File

@ -7,7 +7,7 @@ const dbBackup = require('../../data/db/backup');
const auth = require('../../services/auth');
const apiMail = require('./index').mail;
const apiSettings = require('./index').settings;
const UsersService = require('../../services/users');
const UsersService = require('../../services/Users');
const userService = new UsersService({dbBackup, models, auth, apiMail, apiSettings});
const ALLOWED_INCLUDES = ['count.posts', 'permissions', 'roles', 'roles.permissions'];
const UNSAFE_ATTRS = ['status', 'roles'];

View File

@ -1,3 +1,4 @@
/* eslint-disable ghost/filenames/match-regex */
const Promise = require('bluebird');
const validator = require('@tryghost/validator');
const debug = require('@tryghost/debug')('api:endpoints:utils:validators:input:passwordreset');

View File

@ -1,6 +1,6 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('importer:roles');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const {activate} = require('../../../../services/themes/activate');
const {sequence} = require('@tryghost/promise');

View File

@ -1,6 +1,6 @@
const debug = require('@tryghost/debug')('importer:newsletters');
const _ = require('lodash');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const ignoredColumns = ['sender_email'];

View File

@ -1,7 +1,7 @@
const debug = require('@tryghost/debug')('importer:posts');
const _ = require('lodash');
const uuid = require('uuid');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const mobiledocLib = require('../../../../lib/mobiledoc');
const validator = require('@tryghost/validator');
const postsMetaSchema = require('../../../schema').tables.posts_meta;

View File

@ -1,5 +1,5 @@
const _ = require('lodash');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const debug = require('@tryghost/debug')('importer:products');

View File

@ -1,5 +1,5 @@
const debug = require('@tryghost/debug')('importer:revue-subscriber');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const papaparse = require('papaparse');
const path = require('path');

View File

@ -1,5 +1,5 @@
const debug = require('@tryghost/debug')('importer:roles');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
class RolesImporter extends BaseImporter {
constructor(allDataFromFile) {

View File

@ -1,7 +1,7 @@
const debug = require('@tryghost/debug')('importer:settings');
const ObjectId = require('bson-objectid').default;
const _ = require('lodash');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const defaultSettings = require('../../../schema').defaultSettings;
const keyGroupMapper = require('../../../../api/endpoints/utils/serializers/input/utils/settings-key-group-mapper');

View File

@ -1,6 +1,6 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('importer:stripeprices');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
class StripePricesImporter extends BaseImporter {

View File

@ -1,6 +1,6 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('importer:stripeproducts');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
class StripeProductsImporter extends BaseImporter {

View File

@ -1,6 +1,6 @@
const debug = require('@tryghost/debug')('importer:tags');
const _ = require('lodash');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const {sequence} = require('@tryghost/promise');

View File

@ -1,6 +1,6 @@
const debug = require('@tryghost/debug')('importer:users');
const _ = require('lodash');
const BaseImporter = require('./base');
const BaseImporter = require('./Base');
const models = require('../../../../models');
const limitService = require('../../../../services/limits');

View File

@ -5,17 +5,17 @@ const {IncorrectUsageError} = require('@tryghost/errors');
const debug = require('@tryghost/debug')('importer:data');
const {sequence} = require('@tryghost/promise');
const models = require('../../../../models');
const PostsImporter = require('./posts');
const TagsImporter = require('./tags');
const SettingsImporter = require('./settings');
const UsersImporter = require('./users');
const NewslettersImporter = require('./newsletters');
const ProductsImporter = require('./products');
const StripeProductsImporter = require('./stripe-products');
const StripePricesImporter = require('./stripe-prices');
const CustomThemeSettingsImporter = require('./custom-theme-settings');
const RevueSubscriberImporter = require('./revue-subscriber');
const RolesImporter = require('./roles');
const PostsImporter = require('./PostsImporter');
const TagsImporter = require('./TagsImporter');
const SettingsImporter = require('./SettingsImporter');
const UsersImporter = require('./UsersImporter');
const NewslettersImporter = require('./NewslettersImporter');
const ProductsImporter = require('./ProductsImporter');
const StripeProductsImporter = require('./StripeProductsImporter');
const StripePricesImporter = require('./StripePricesImporter');
const CustomThemeSettingsImporter = require('./CustomThemeSettingsImporter');
const RevueSubscriberImporter = require('./RevueSubscriberImporter');
const RolesImporter = require('./RolesImporter');
const {slugify} = require('@tryghost/string/lib');
let importers = {};

View File

@ -1,3 +1,4 @@
/* eslint-disable ghost/filenames/match-regex */
const Promise = require('bluebird');
module.exports = function afterEach() {

View File

@ -1,3 +1,4 @@
/* eslint-disable ghost/filenames/match-regex */
const Promise = require('bluebird');
module.exports = function beforeEach() {

View File

@ -1,6 +1,6 @@
const logging = require('@tryghost/logging');
const {createTransactionalMigration} = require('../../utils');
const MembersConfigProvider = require('../../../../services/members/config');
const MembersConfigProvider = require('../../../../services/members/MembersConfigProvider');
const settingsCache = require('../../../../../shared/settings-cache');
const config = require('../../../../../shared/config');

View File

@ -1,4 +1,4 @@
const FixtureManager = require('./fixture-manager');
const FixtureManager = require('./FixtureManager');
const config = require('../../../../shared/config');
const fixturePath = config.get('paths').fixtures;

View File

@ -1,7 +1,7 @@
const BlogIcon = require('./blog-icon');
const CachedImageSizeFromUrl = require('./cached-image-size-from-url');
const Gravatar = require('./gravatar');
const ImageSize = require('./image-size');
const BlogIcon = require('./BlogIcon');
const CachedImageSizeFromUrl = require('./CachedImageSizeFromUrl');
const Gravatar = require('./Gravatar');
const ImageSize = require('./ImageSize');
class ImageUtils {
constructor({config, urlUtils, settingsCache, storageUtils, storage, validator, request, cacheStore}) {

View File

@ -5,7 +5,7 @@ const storageUtils = require('../../adapters/storage/utils');
const validator = require('@tryghost/validator');
const config = require('../../../shared/config');
const settingsCache = require('../../../shared/settings-cache');
const ImageUtils = require('./image-utils');
const ImageUtils = require('./ImageUtils');
const adapterManager = require('../../services/adapter-manager');

View File

@ -13,8 +13,8 @@ const adapterManager = new AdapterManager({
});
adapterManager.registerAdapter('storage', require('ghost-storage-base'));
adapterManager.registerAdapter('scheduling', require('../../adapters/scheduling/SchedulingBase'));
adapterManager.registerAdapter('sso', require('../../adapters/sso/Base'));
adapterManager.registerAdapter('scheduling', require('../../adapters/scheduling/scheduling-base'));
adapterManager.registerAdapter('sso', require('../../adapters/sso/SSOBase'));
adapterManager.registerAdapter('cache', require('@tryghost/adapter-base-cache'));
module.exports = {

View File

@ -6,7 +6,7 @@ const settingsCache = require('../../../../shared/settings-cache');
const models = require('../../../models');
const urlUtils = require('../../../../shared/url-utils');
const SessionStore = require('./store');
const SessionStore = require('./SessionStore');
const sessionStore = new SessionStore(models.Session);
let unoExpressSessionMiddleware;

View File

@ -15,8 +15,8 @@ const messages = {
module.exports = class CommentsController {
/**
* @param {import('./service')} service
* @param {import('./stats')} stats
* @param {import('./CommentsService')} service
* @param {import('./CommentsStatsService')} stats
*/
constructor(service, stats) {
this.service = service;

View File

@ -25,7 +25,7 @@ class CommentsService {
/** @private */
this.contentGating = contentGating;
const Emails = require('./emails');
const Emails = require('./CommentsServiceEmails');
/** @private */
this.emails = new Emails({
config,

View File

@ -1,8 +1,8 @@
class CommentsServiceWrapper {
init() {
const CommentsService = require('./service');
const CommentsController = require('./controller');
const CommentsStats = require('./stats');
const CommentsService = require('./CommentsService');
const CommentsController = require('./CommentsController');
const CommentsStats = require('./CommentsStatsService');
const config = require('../../../shared/config');
const logging = require('@tryghost/logging');

View File

@ -2,7 +2,7 @@ const config = require('../../../shared/config');
const urlUtils = require('../../../shared/url-utils');
const DynamicRedirectManager = require('@tryghost/express-dynamic-redirects');
const CustomRedirectsAPI = require('./api');
const CustomRedirectsAPI = require('./CustomRedirectsAPI');
const validation = require('./validation');
const {getBackupRedirectsFilePath} = require('./utils');

View File

@ -1,3 +1,3 @@
const EmailAnalyticsServiceWrapper = require('./wrapper');
const EmailAnalyticsServiceWrapper = require('./EmailAnalyticsServiceWrapper');
module.exports = new EmailAnalyticsServiceWrapper();

View File

@ -1,5 +1,5 @@
const logging = require('@tryghost/logging');
const url = require('../../../server/api/endpoints/utils/serializers/output/utils/url');
const url = require('../../api/endpoints/utils/serializers/output/utils/url');
class EmailServiceWrapper {
getPostUrl(post) {
@ -18,7 +18,7 @@ class EmailServiceWrapper {
const MailgunClient = require('@tryghost/mailgun-client');
const configService = require('../../../shared/config');
const settingsCache = require('../../../shared/settings-cache');
const settingsHelpers = require('../../services/settings-helpers');
const settingsHelpers = require('../settings-helpers');
const jobsService = require('../jobs');
const membersService = require('../members');
const db = require('../../data/db');

View File

@ -1,3 +1,3 @@
const EmailServiceWrapper = require('./wrapper');
const EmailServiceWrapper = require('./EmailServiceWrapper');
module.exports = new EmailServiceWrapper();

View File

@ -1,4 +1,4 @@
const ExploreService = require('./service');
const ExploreService = require('./ExploreService');
const MembersService = require('../members');
const PostsService = require('../posts/posts-service')();

View File

@ -1,5 +1,5 @@
const models = require('../../models');
const FrontendDataService = require('./frontend-data-service');
const FrontendDataService = require('./FrontendDataService');
module.exports.init = () => {
return new FrontendDataService({IntegrationModel: models.Integration});

View File

@ -2,7 +2,7 @@ const settingsCache = require('../../../shared/settings-cache');
const settingsHelpers = require('../settings-helpers');
const mailService = require('../../services/mail');
const urlUtils = require('../../../shared/url-utils');
const Invites = require('./invites');
const Invites = require('./Invites');
module.exports = new Invites({
settingsCache,

Some files were not shown because too many files have changed in this diff Show More