no-unknown-files
Prevent creating files not recognized by any element or file descriptor pattern.
Rule Details
This rule reports files that your architecture does not recognize at all. A file is reported as an error only when it matches no file descriptor pattern and belongs to no known element. If either check recognizes the file, it is not reported.
There are two independent ways for a file to be recognized:
- It belongs to an element defined in
boundaries/elements(an element descriptor). - It matches a file descriptor defined in
boundaries/files.
File descriptors categorize files independently of elements. A file that matches any file descriptor pattern is considered known by this rule even if it belongs to no element. This is useful for files that are part of your project but do not form an architectural element on their own, such as test files, stylesheets, or configuration files.
A file that is excluded from analysis through boundaries/ignore is never reported, because ignored files are not analyzed.
Options
"boundaries/no-unknown-files": [<severity>]
This rule has no options. The only value is the ESLint severity: 0 = off, 1 = warning, 2 = error.
Configuration Example
{
rules: {
"boundaries/no-unknown-files": [2]
}
}
Settings
The following examples use this project structure and settings configuration.
Project structure:
src/
├── helpers/
│ ├── data/
│ │ ├── sort.js
│ │ └── parse.js
│ └── permissions/
│ └── roles.js
├── setup.spec.js
├── foo.js
└── index.js
Settings configuration:
This configuration recognizes files in two ways. The boundaries/elements setting defines the helper element, and the boundaries/files setting categorizes *.spec.js files as test and src/index.js as root. As a result, the spec file and index.js are recognized even though they belong to no element.
{
settings: {
"boundaries/elements": [
{
type: "helper",
pattern: "helpers/*",
capture: ["family"]
}
],
"boundaries/files": [
{ pattern: "**/*.spec.js", category: "test" },
{ pattern: "src/index.js", category: "root" }
]
}
}
Examples
Incorrect
Unrecognized foo.js file. It matches no element and no file descriptor:
// src/foo.js
Correct
A helper file that belongs to the helper element:
// src/helpers/data/sort.js
A spec file that belongs to no element, but matches the test file descriptor, so it is recognized:
// src/setup.spec.js
A file matched by a file descriptor instead of an element. src/index.js matches the root file descriptor:
// src/index.js
Error Messages
Default error message:
File does not match any file pattern and does not belong to any known element
Further Reading
Read next sections to learn more about related topics:
- Defining Elements - Learn how to define architectural elements in your project
- File Descriptors - Learn how to categorize files independently of elements
- Selectors - Learn about element, file, and module selectors used in rules
- Policies - Learn how to configure rule options and custom messages
- Global Settings - Learn about global settings, including
boundaries/files