Skip to content
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

Kramdown warnings #967

Merged
merged 2 commits into from Oct 29, 2016
Merged

Kramdown warnings #967

merged 2 commits into from Oct 29, 2016

Conversation

@gpakosz
Copy link
Member

@gpakosz gpakosz commented Oct 23, 2016

Summary

This PR does two things in two commits:

  • tell which item and rep produces a kramdown warning
  • implements warning filtering (see #675) as kramdown itself as no warning switches

To do

The :warning_filters array should be documented on https://nanoc.ws as part of the filters reference documentation.


# Run filter
io = capturing_stdio do
filter.setup_and_run('{:foo}this is bogus')
end
assert_empty io[:stdout]
assert_equal "kramdown warning: Found span IAL after text - ignoring it\n", io[:stderr]
assert_equal "kramdown warning(s) for item, rep: #{item.identifier}, #{item_rep.name}\n Found span IAL after text - ignoring it\n", io[:stderr]
Copy link
Member

@ddfreyne ddfreyne Oct 23, 2016

Choose a reason for hiding this comment

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

I’d replace

"… item, rep: #{item.identifier}, #{item_rep.name}"

with

"… #{item_rep.inspect}"

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Oct 23, 2016

Looks good! There’s a couple of style issues that Travis CI complains about still.

Loading

warnings = document.warnings
end

if warnings.length != 0
Copy link
Member

@ddfreyne ddfreyne Oct 23, 2016

Choose a reason for hiding this comment

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

Replace this with warnings.any? (I know Rubocop says warnings.length.nonzero? but that’s not as nice.)

Loading

$stderr.puts "kramdown warning: #{warning}"
if (warning_filters)
r = Regexp.union(warning_filters)
warnings = document.warnings.select { |warning| !(r =~ warning) }
Copy link
Member

@ddfreyne ddfreyne Oct 23, 2016

Choose a reason for hiding this comment

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

Replace

!(r =~ warning)

with

r !~ warning

Or alternatively, replace

select { |warning| !(r =~ warning) }

with

reject { |warning| r =~ warning }

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Oct 23, 2016

Does it make sense to provide the warning filters via the configuration file, rather than arguments to the filter call? That’d make the dup dance unnecessary, and I guess it’d avoid having to copy the filter warnings if you call the :kramdown filter more than once…

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Oct 23, 2016

I took your comments into account.

Well in my setup, I was already doing e.g in nanoc.yaml.

# erb filter options
erb:
  trim_mode: '<>'

and then when filtering

filter :erb, @config[:erb] || {}

A quick grep didn't really exhibit existing filters reading their options straight from @config, do you want to introduce a new behavior? (which kinda opens other questions like @config[:kramdown][:warning_filters] or @config[:kramdown_warning_filters] 🤔 ?)

Loading

@gpakosz gpakosz force-pushed the kramdown-warnings branch from fc1ec10 to e30fdf3 Oct 26, 2016
@connorshea
Copy link

@connorshea connorshea commented Oct 27, 2016

This is awesome, I've wanted this myself. Thanks @gpakosz!

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Oct 29, 2016

I’m OK with leaving it as a filter argument, as it’s more flexible, and still leaves open the option for using the configuration in the way you described.

Is this still WIP or is it ready to go?

Loading

@ddfreyne ddfreyne merged commit e51fb4b into nanoc:master Oct 29, 2016
1 check passed
Loading
@gpakosz gpakosz deleted the kramdown-warnings branch Feb 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants