{"record":{"id":"bdf3758ff7d31a53","repo":"rectorphp/rector","slug":"rule-s-was-not-found-sthe-rule-has-no-namespac","errorCode":null,"errorMessage":"Rule \"%s\" was not found.%sThe rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only=\"My\\Rector\\Rule\"","messagePattern":"Rule \"(.+?)\" was not found\\.(.+?)The rule has no namespace\\. Make sure to escape the backslashes, and add quotes around the rule name: --only=\"My\\\\Rector\\\\Rule\"","errorType":"exception","errorClass":"RectorRuleNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Configuration/OnlyRuleResolver.php","lineNumber":77,"sourceCode":"            $flattenMatching = [];\n            foreach ($this->rectors as $rector) {\n                if (str_replace('\\\\', '', get_class($rector)) === $rule) {\n                    $flattenMatching[] = get_class($rector);\n                }\n            }\n            $flattenMatching = array_unique($flattenMatching);\n            if (count($flattenMatching) === 1) {\n                return $flattenMatching[0];\n            }\n            $message = sprintf('Rule \"%s\" was not found.%sThe rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only=\"My\\Rector\\Rule\"', $rule, \\PHP_EOL);\n        } else {\n            // the rule class exists, it is just missing in the config\n            if ($this->isRectorRuleClass($rule)) {\n                throw new RectorRuleNotFoundException($this->createUnregisteredMessage($rule));\n            }\n            $message = sprintf('Rule \"%s\" was not found.%sMake sure it is registered in your config or in one of the sets', $rule, \\PHP_EOL);\n        }\n        throw new RectorRuleNotFoundException($message);\n    }\n    /**\n     * Is this an existing rule class, that is just not registered in the config?\n     */\n    private function isRectorRuleClass(string $className): bool\n    {\n        if (!class_exists($className)) {\n            return \\false;\n        }\n        $reflectionClass = new ReflectionClass($className);\n        if ($reflectionClass->isAbstract()) {\n            return \\false;\n        }\n        return $reflectionClass->implementsInterface(RectorInterface::class);\n    }\n    private function createUnregisteredMessage(string $ruleClass): string\n    {\n        $shortRuleClass = (string) substr((string) strrchr($ruleClass, '\\\\'), 1);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Configuration/OnlyRuleResolver.php#L59-L95","documentation":"If the --only value contains no backslash at all, the shell has likely eaten the namespace separators (e.g. --only=\\Rector\\Some\\Rule collapsing to RectorSomeRule after double-quote processing or Windows quoting). OnlyRuleResolver then throws RectorRuleNotFoundException explaining the value has no namespace and shows the correct quoting form. The resolver even tries a backslash-stripped comparison first, so reaching this error means that also found nothing.","triggerScenarios":"Passing --only=Rector\\Php81\\Rector\\FuncCall\\ReadOnlyPropertyRector without quotes so the shell strips \\R etc.; Windows cmd single-quoting artifacts (leading/trailing quotes are stripped automatically, but mangled separators are not); double-escaped \\\\ inputs on exotic shells.","commonSituations":"Copy-pasting a FQCN from docs into a bash/zsh command without wrapping it in quotes; CI YAML where backslashes need careful escaping; PowerShell mangling backslashes.","solutions":["Quote the argument exactly as the message shows: --only=\"My\\Rector\\Rule\" (double quotes on Unix shells)","In CI YAML, prefer single-quoted YAML scalars so backslashes survive: '--only=\"My\\Rector\\Rule\"'","Alternatively avoid shell entirely: put the rule in withRules() and run without --only"],"exampleFix":"# before: unquoted backslashes get eaten by the shell\nvendor/bin/rector process src --only=Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector\n\n# after: quote the whole class name\nvendor/bin/rector process src --only=\"Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector\"","handlingStrategy":"validation","validationCode":"// wrapper-side check before invoking rector\n$only = (string) getopt('', ['only:'])['only'] ?? '';\nif (strpos($only, '\\\\') !== false || (strpos($only, '\\') === false && preg_match('/^[A-Z]/', $only))) {\n    fwrite(STDERR, \"--only needs a quoted FQCN, e.g. --only=\\\"My\\\\Rector\\\\Rule\\\"\\n\");\n}","typeGuard":"function isWellFormedRuleName(string $rule): bool\n{\n    return strpos($rule, '\\\\') === false && strpos($rule, '\\') !== false;\n}","tryCatchPattern":"catch \\Rector\\Exception\\Configuration\\RectorRuleNotFoundException; if the message says 'The rule has no namespace', re-run with the value double-quoted: --only=\"My\\Rector\\Rule\".","preventionTips":["Always double-quote FQCN arguments on Unix shells: --only=\"Vendor\\Package\\Rule\"","In CI YAML use single-quoted scalars so backslashes need no doubling","On Windows, remember OnlyRuleResolver strips wrapping single quotes but cannot restore eaten separators"],"tags":["php","rector","cli","shell-escaping","rule-selection","windows"],"backgroundTag":"cli-argument-escaping","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}