@krknet/eslint-plugin
v2.1.0
Published
KRKnet Standard Rules
Readme
@krknet/eslint-plugin
KRKnet ESLint rules and flat-config helpers for Node, Vue frontend, and SuiteScript projects.
Requirements
- Node.js >= 22.12
- ESLint ^9
Installation
npm install --save-dev eslint @krknet/eslint-pluginQuick Start (Flat Config)
Create or update your ESLint config:
// eslint.config.mjs
import {
createBase,
createNode,
createFrontend,
plugin
} from '@krknet/eslint-plugin'
export default [
...createBase(),
...createNode(),
...createFrontend({ tailwindPath: './app/frontend/layout/main.css' }),
// Optional: manual rule setup for custom rule usage in other file groups.
{
files: ['**/*.vue'],
plugins: {
krk: plugin
},
rules: {
'krk/vue-html-linebreak': 'warn',
'krk/vue-sort-components': 'warn'
}
}
]Exports
This package exports:
plugin: ESLint plugin object (rules,configs)rules: custom rule mapconfigs: config factory mapcreateBase(options?)returns a config arraycreateNode(options?)returns three config entries (CJS, ESM, and tooling exceptions)createNodeCjs(options?)returns one config objectcreateNodeEsm(options?)returns one config objectcreateFrontend(options?)returns a config arrayfrontendFilescreateSuiteScriptBase()returns one config object (deprecated compatibility helper)createSuiteScriptBuild(options?)returns a config arraycreateSuiteScriptSource(options?)returns a config array
Spread array-returning factories into a flat config. Add object-returning factories directly.
Config Helpers
createBase
Shared baseline config. It always disables @stylistic/multiline-ternary and enables krk/ternary-line-length with { merge: 120, split: false }.
Options:
ignoresadds ignore patterns.
Customize or disable the KRK rule with a later flat-config entry:
{
rules: {
'krk/ternary-line-length': ['warn', {
merge: 100,
split: 120
}]
}
}createNode
Returns an array with dedicated configs for CommonJS and ESM Node files.
By default, it covers Node files under app, build, cli, tests, and tools, along with eslint.config.{js,cjs,mjs}.
Build scripts, tests, tools, and ESLint config files may import development dependencies. The generated config disables n/no-unpublished-import and n/no-unpublished-require for those conventional tooling paths while keeping application and CLI files strict.
Options:
cjsFilesoverrides the CommonJS file patterns.esmFilesoverrides the ESM file patterns.ignoresadds ignore patterns to both entries.aliases(default{ '>': './app' })rules(applies to both CJS and ESM entries)cjsRules(CJS-only overrides)esmRules(ESM-only overrides)pluginssettings(merged with the generated resolver settings;nandimport/resolverkeys are merged one level deep, so addingsettings.n.versionkeeps the generated aliasresolverConfig)
createNodeCjs and createNodeEsm accept files and ignores directly, in addition to the shared options.
files, cjsFiles and esmFiles replace the defaults rather than adding to them. Import nodeCjsFiles and nodeEsmFiles to extend them instead:
import { createNode, nodeCjsFiles } from '@krknet/eslint-plugin'
createNode({ cjsFiles: [...nodeCjsFiles, 'server/**/*.js'] })createFrontend
Vue-focused config with import ordering, Vue rules, Tailwind rules, and KRK custom rules.
Options:
filesreplaces the default frontend file patterns.tailwindPath(optional better-tailwindcss entry point)aliases(default{ '@': './app/frontend/components', '>': './app' })pluginsrulessettings
Import frontendFiles to extend the defaults instead:
import { createFrontend, frontendFiles } from '@krknet/eslint-plugin'
createFrontend({ files: [...frontendFiles, 'client/**/*.mjs'] })Frontend imports are checked with import/no-unresolved. Extensionless .vue imports are supported alongside .mjs, .js, and .json.
Direct imports of globally registered v-* entry points are rejected. Nested subcomponents and supporting modules remain importable.
Prefer Vue's expose option for properties and methods that parents access through component refs. For public members used through contracts that expose would misrepresent, use /** @public @mixin ... */ for mixin contracts or /** @public @dynamic ... */ for reflective access. On Options API methods and computed properties, krk/vue-prefer-expose reports plain @public annotations and redundant annotations on exposed members. The frontend config ignores documented public members when checking vue/no-unused-properties; ordinary unused members are still reported.
createSuiteScriptBuild / createSuiteScriptSource
createSuiteScriptBuild returns an array containing the Node ESM config for suitescripts/build.mjs. Resolver-dependent import cycle, duplicate, and ordering checks are disabled for the build script because the legacy alias resolver cannot load some ESM-only build dependencies. The build script may also import development dependencies such as Rollup plugins, so n/no-unpublished-import is disabled for it.
Pass files when the build script lives elsewhere; the default is exported as suiteScriptBuildFiles:
createSuiteScriptBuild({ files: ['tools/bundle-suitescripts.mjs'] })createSuiteScriptSource returns a config array for SuiteScript source files. A single-target project rooted at suitescripts/src needs no options:
export default [
...createBase(),
...createNode(),
...createSuiteScriptBuild(),
...createSuiteScriptSource()
]SuiteScript .mjs files are parsed as modules, .js files as scripts, and .cjs files as CommonJS. Node and browser globals are unavailable by default. Files matching **/*.{cs,CS}.js are treated as NetSuite ClientScripts and receive browser globals. Use clientFiles to replace that default when a project follows another naming convention:
createSuiteScriptSource({
clientFiles: ['suitescripts/src/client/**/*.js']
})For repositories containing multiple SuiteScript targets, list each target. Shared aliases remain available everywhere, while @ resolves to the matching target within target files:
export default [
...createBase(),
...createNode(),
...createSuiteScriptBuild(),
...createSuiteScriptSource({
targets: ['SPE', 'SPUS'],
aliases: {
'@common': './suitescripts/src/common',
'@lib': './suitescripts/src/lib'
}
})
]Use root when SuiteScript source lives somewhere other than ./suitescripts/src. Absolute paths are resolved against the working directory. The normalized root is used for the file globs, and a project-relative form of it becomes the @ alias target.
Alias targets may be written with or without a leading ./, or as absolute paths. They are normalized before reaching eslint-import-resolver-alias, which would otherwise treat a target such as suitescripts/src/lib as a package name to look up in node_modules.
createSuiteScriptBase is deprecated. It remains available for legacy bundle entry points directly under suitescripts, but ignores source, distribution output, and suitescripts/build.mjs. Standard layouts should use createSuiteScriptBuild and createSuiteScriptSource.
Supported Rules
krk/ternary-line-length
Keeps short ternaries on one line and splits long ternaries with leading ? and : operators. It supports JavaScript and Vue template expressions.
Options:
merge: Merge a multiline ternary when the complete line is at or below this length. Usefalseto disable merging.split: Split an inline or partially split ternary when the complete line exceeds this length. Usefalseto disable splitting.
Each omitted threshold defaults to 120. When merge is lower than split, layouts within the gap are left unchanged. A merge value above split is capped at the split threshold to prevent autofix loops.
{
rules: {
'krk/ternary-line-length': ['warn', {
merge: 100,
split: 120
}]
}
}krk/vue-html-linebreak
Enforces splitting long Vue start tags into one-attribute-per-line form and merges short multiline tags back to one line.
Options:
splitnumber (default80)mergenumber (default50)
Example:
{
rules: {
'krk/vue-html-linebreak': ['warn', { split: 100, merge: 60 }]
}
}krk/vue-prefer-expose
Prefers Vue's expose option for Options API methods and computed properties used through parent refs. A plain @public annotation is reported; reserve @public @mixin and @public @dynamic for contracts that cannot be represented accurately by expose. An @public annotation is also reported when the same member is already listed in expose.
This rule has no options and does not autofix.
export default {
expose: ['focus'],
methods: {
focus () {},
/** @public @mixin Required by a mixin contract. */
refresh () {}
}
}krk/vue-sort-components
Sorts component registration keys in Vue components objects.
Options:
'asc'(default)'desc'
Example:
{
rules: {
'krk/vue-sort-components': ['warn', 'asc']
}
}