2019-05-03 08:17:27 +10:00
# frozen_string_literal: true
2018-07-26 10:25:40 -04:00
if github . pr_json && ( github . pr_json [ "additions" ] || 0 ) > 250 || ( github . pr_json [ "deletions" ] || 0 ) > 250
2018-07-25 14:36:09 -04:00
warn ( "This pull request is big! We prefer smaller PRs whenever possible, as they are easier to review. Can this be split into a few smaller PRs?" )
2018-07-24 10:12:15 -04:00
end
2018-09-17 15:10:00 +08:00
prettier_offenses = `yarn --silent prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.es6" "test/javascripts/**/*.es6"` . split ( " \n " )
unless prettier_offenses . empty?
2018-07-24 10:12:15 -04:00
fail ( %{
2018-07-26 15:45:01 -04:00
This PR doesn't match our required code formatting standards, as enforced by prettier.io. <a href='https://meta.discourse.org/t/prettier-code-formatting-tool/93212'>Here's how to set up prettier in your code editor.</a> \n
2018-07-26 11:03:36 -04:00
#{ prettier_offenses . map { | o | github . html_link ( o ) } . join ( " \n " ) }
2018-07-24 10:12:15 -04:00
} )
end
2018-11-19 10:00:17 +01:00
2019-05-15 23:43:00 +02:00
locales_changes = git . modified_files . grep ( %r{config/locales} )
has_non_en_locales_changes = locales_changes . grep_v ( %r{config/locales/(?:client|server)\.(?:en|en_US)\.yml} ) . any?
2018-11-19 10:00:17 +01:00
2018-11-21 10:13:25 +01:00
if locales_changes . any? && has_non_en_locales_changes
2018-11-19 10:00:17 +01:00
fail ( "Please submit your non-English translation updates via [Transifex](https://www.transifex.com/discourse/discourse-org/). You can read more on how to contribute translations [here](https://meta.discourse.org/t/contribute-a-translation-to-discourse/14882)." )
end
2019-01-19 10:05:51 +01:00
files = ( git . added_files + git . modified_files )
2019-01-21 12:23:18 +01:00
. select { | path | ! path . start_with? ( "plugins/" ) }
. select { | path | path . end_with? ( "es6" ) || path . end_with? ( "rb" ) }
2019-01-19 10:05:51 +01:00
2019-03-04 13:03:59 +01:00
js_files = files . select { | path | path . end_with? ( ".js.es6" ) }
js_test_files = js_files . select { | path | path . end_with? ( "-test.js.es6" ) }
2019-02-25 16:04:55 +01:00
2019-01-19 10:05:51 +01:00
super_offenses = []
2019-03-04 13:03:59 +01:00
self_offenses = []
js_files . each do | path |
2019-01-19 10:05:51 +01:00
diff = git . diff_for_file ( path )
next if ! diff
diff . patch . lines . grep ( /^\+\s\s/ ) . each do | added_line |
super_offenses << path if added_line [ 'this._super()' ]
2019-03-29 08:50:18 +01:00
self_offenses << path if added_line [ /(?:(^|\W)self\.?)/ ]
2019-01-19 10:05:51 +01:00
end
end
2019-03-04 13:03:59 +01:00
jquery_find_offenses = []
2019-02-25 16:04:55 +01:00
js_test_files . each do | path |
diff = git . diff_for_file ( path )
next if ! diff
diff . patch . lines . grep ( /^\+\s\s/ ) . each do | added_line |
jquery_find_offenses << path if added_line [ 'this.$(' ]
end
end
2019-03-04 13:03:59 +01:00
if ! self_offenses . empty?
warn ( %{
2019-03-29 08:50:18 +01:00
Use fat arrow instead of self pattern. \n
2019-03-04 13:03:59 +01:00
#{ self_offenses . uniq . map { | o | github . html_link ( o ) } . join ( " \n " ) }
} )
end
2019-01-19 10:05:51 +01:00
if ! super_offenses . empty?
warn ( %{
When possible use `this._super(...arguments)` instead of `this._super()` \n
#{ super_offenses . uniq . map { | o | github . html_link ( o ) } . join ( " \n " ) }
} )
end
2019-02-25 16:04:55 +01:00
if ! jquery_find_offenses . empty?
warn ( %{
Use `find()` instead of `this.$` in js tests` \n
#{ jquery_find_offenses . uniq . map { | o | github . html_link ( o ) } . join ( " \n " ) }
} )
end