Shopify / theme-check

The Ultimate Shopify Theme Linter
Other
333 stars 96 forks source link

CdnPreconnect.rb missing in theme-check-1.15 gem #749

Closed stevekaran closed 8 months ago

stevekaran commented 8 months ago

(sorry in advance for the long explanation, want to be thorough...)

I use VSCode on Windows to build and debug Shopify themes. I have installed the Shopify Liquid VSCode extension, which requires Shopify CLI and Theme CLI. I installed all prerequisites (NodeJS, Ruby, etc...) and everything appeared to be working well. I then downloaded the config file default.yml, and placed it my theme directory. As soon as the config was read, the Theme Language Server would crash and the extension would stop working. Running shopify theme check --verbose revealed the following Ruby error:

D:\Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:121:in 'block in enabled_checks': uninitialized constant **ThemeCheck::CdnPreconnect (NameError)**

        check_class = ThemeCheck.const_get(check_name)
                                ^^^^^^^^^^
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:118:in `each'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:118:in `map'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:118:in `enabled_checks'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/diagnostics_engine.rb:25:in `analyze_and_send_offenses'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/handler.rb:278:in `analyze_and_send_offenses'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/handler.rb:114:in `on_text_document_did_change'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:138:in `handle_message'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:109:in `block in handle_messages'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:105:in `loop'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:105:in `handle_messages'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:99:in `block (2 levels) in start_handler_threads'
Closing server... status code = 2`

This CdnPreconnect option is included in default.yml, and upon removing it (comment or delete), the Theme Language Server starting working again, as did the extension. Upon researching the problem, from cdnpreconnect.md, it makes reference to cdnpreconnect.rb. I checked my local theme-check 1.15 gem installation and cdnpronnect.rb is missing. I redownloaded the theme-check 1.15 gem from rubygems.org, unpacked the gem, and cdnpreconnect.rb is still missing.

Please update the theme-check gem to ensure cdnreconnect.rb is included (as well as any other missing rubies/files). I have since downloaded cdnreconnect.rb from this repo and placed in my gem library.

stevekaran commented 8 months ago

Since adding cdnreconnect.rb to my gem repository, now I get a psych parser error 🤦‍♂️

D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych/parser.rb:62:in `_native_parse': (.theme-check.yml): did not find expected key while parsing a block mapping at line 1 column 1 (Psych::SyntaxError)
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych/parser.rb:62:in `parse'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:455:in `parse_stream'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:399:in `parse'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:323:in `safe_load'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:369:in `load'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:671:in `block in load_file'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:670:in `open'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/psych-5.1.1.1/lib/psych.rb:670:in `load_file'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:43:in `load_file'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:63:in `load_config'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/config.rb:17:in `from_path'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/handler.rb:274:in `config_for_path'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/handler.rb:221:in `in_memory_storage'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/handler.rb:68:in `on_initialize'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:138:in `handle_message'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:80:in `block (2 levels) in start_json_rpc_thread'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:77:in `loop'
    from D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/theme-check-1.15.0/lib/theme_check/language_server/server.rb:77:in `block in start_json_rpc_thread'
[Error - 10:52:15 PM] Server initialization failed.
  Message: A theme-check-language-server has occured, inspect OUTPUT logs for details.
  Code: -32603 
[Error - 10:52:15 PM] Theme Check Language Server client: couldn't create connection to server.

If I rename my .\theme-check.yml, the server and extension start working again. I guess there's more work to do that just adding a missing file 🤷‍♂️

charlespwd commented 8 months ago

That's because CdnPreconnect isn't released in the ruby version yet. It was added after 1.15. You can remove it from your .theme-check.yml file for the time being or use the "shopifyLiquid.themeCheckNextDevPreview": true VS Code extension setting to use the next version of theme-check that does include it.