Open DawMatt opened 1 year ago
Described behavior & workaround confirmed with Spectral CLI version 6.6.0, installed via NPM 9.5.1 on Windows 10, Node.js v18.16.0
echo 'extends: ["spectral:oas", "spectral:asyncapi"]' > .spectral.yaml
in PoweShell => UTF-16 LE-BOM
=> ❌ echo 'extends: ["@apisyouwonthate/style-guide"]' | Out-File .spectral.yaml
in PoweShell => UTF-16 LE-BOM
=> ❌ echo 'extends: ["@apisyouwonthate/style-guide"]' | Out-File .spectral.yaml -Encoding ascii
in PowerShell => UTF-8
=> 👍 echo extends: ["spectral:oas", "spectral:asyncapi"] > .spectral.yaml
(without quotes) in CMD => UTF-8
=> 👍 i spend bunch of time to get the reason definitly your comment helps me a lot @ravage84 , So powerShell user : echo 'extends: ["spectral:oas"]' | Out-File .spectral.yaml -Encoding ascii
Describe the bug If you follow the readme instruction 1 (create a local ruleset) using Powershell on Windows, it generates a .spectral.yaml file using UTF16-LE encoding. Spectral reports
Error running Spectral!
when linting and using this file.To Reproduce
echo 'extends: ["spectral:oas", "spectral:asyncapi"]' > .spectral.yaml
spectral lint someopenapifile.yaml --verbose
, replacingsomeopenapifile.yaml
with the name of the file selected in the previous stepExpected behavior Spectral would lint the OpenAPI using the ruleset created according to the usage instructions.
Screenshots Please refer to the error text above.
Environment (remove any that are not applicable):
Additional context This was discovered due to the same issue being present in the Visual Studio Code extension and the Spectral Documentation Ruleset.
There appears to be a superficial fix or a deeper fix available for this issue.
Superficial fix would be to update all of the readmes (including the additional repositories linked above) to make it clear a different approach is required for creating a local ruleset using Powershell. A command like this:
creates a configuration file using UTF8 and Spectral will lint using this.
A deeper fix would be to support additional file encodings, even if only by forcing them to UTF8 before processing.
@philsturgeon , I've create this new bug in the main spectral repository instead of reopening https://github.com/stoplightio/spectral-documentation/issues/3 as issue impacts multiple spectral repositories.