Skip to content

New feature : linting #2557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Apr 12, 2025

This PR adds a linting feature that can activated through Grape.config.lint = true or lint! in a Grape::Api.
Suggested in this comment.

By design, Grape's CI has Grape.config.lint = true, so all specs calling an endpoint are linted.

@dblock
Copy link
Member

dblock commented Apr 12, 2025

Should we call it lint! since it's Rack::Lint?

But thinking about it, maybe we need something more generic that allows one to inject middleware here, including potentially the ability to remove Rack::Head?

@ericproulx
Copy link
Contributor Author

Should we call it lint! since it's Rack::Lint?

But thinking about it, maybe we need something more generic that allows one to inject middleware here, including potentially the ability to remove Rack::Head?

The middleware stack lacks a delete function. I think we should do something like ActionDispatch::MiddlewareStack

@ericproulx ericproulx marked this pull request as ready for review April 13, 2025 16:32
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this in the README if you want it merged.

That said, also consider not merging this and doing a configurable middleware implementation instead.

@ericproulx ericproulx requested a review from Copilot May 1, 2025 16:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new linting feature into the Grape framework, allowing endpoints to be linted by default or via a per-endpoint configuration. Key changes include:

  • Enabling the global lint configuration in spec_helper and lib/grape.
  • Incorporating Rack::Lint middleware in the endpoint stack when linting is enabled.
  • Adding a new DSL method lint! to allow per-endpoint lint configuration.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/spec_helper.rb Enables linting globally by setting Grape.config.lint to true.
spec/integration/rails/mounting_spec.rb Modifies Rails app instantiation and wraps the app with Rack::Lint.
spec/grape/api_spec.rb Adds tests for the new .lint! behavior and Rack::Lint error handling.
lib/grape/endpoint.rb Inserts Rack::Lint middleware conditionally and defines a lint? method.
lib/grape/dsl/routing.rb Introduces lint! in the DSL for endpoint-specific lint enabling.
lib/grape.rb Sets the default lint configuration to false.
Files not reviewed (1)
  • docker/Dockerfile: Language not supported

@ericproulx
Copy link
Contributor Author

Please document this in the README if you want it merged.

That said, also consider not merging this and doing a configurable middleware implementation instead.

I like the lint! DSL since we can configure our entire CI to use it by default. The configurable middleware seems a good idea but I don't know how we would enforce this in the CI without adding it in every call in every specs. It's already possible to do add Rack::Lint so to by calling:

insert_before Grape::Middleware::Error, Rack::Lint

I think the lint! really ease the whole thing.

@ericproulx ericproulx requested a review from dblock May 1, 2025 17:26
@ericproulx ericproulx force-pushed the feature_rack_lint branch 2 times, most recently from 5d45776 to fad6b2e Compare May 1, 2025 17:47
Fix typo in UPGRADING.md
@ericproulx ericproulx force-pushed the feature_rack_lint branch from fad6b2e to ed493d0 Compare May 1, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants