UNPKG

eslint-plugin-mdx

Version:
32 lines • 1.16 kB
import path from 'node:path'; import { getRuleConfig } from './helpers.js'; export const noFileNameIrregularCharacters = { meta: { type: 'problem', docs: { description: 'Disallow irregular characters in file names', }, schema: [{ type: ['string', 'object', 'null'] }], }, create(context) { const config = getRuleConfig(context, 'no-file-name-irregular-characters'); if (!config) { return {}; } const expected = config.options == null ? /[^-.\dA-Za-z]/u : typeof config.options === 'string' ? new RegExp(`[^${config.options}]`, 'u') : config.options; const stem = path.basename(context.filename, path.extname(context.filename)); const match = expected.exec(stem); if (match) { context.report({ loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } }, message: `Unexpected character \`${match[0]}\` in file name`, }); } return {}; }, }; //# sourceMappingURL=no-file-name-irregular-characters.js.map