Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Fixes violations for CodeNarc Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rainboyan committed Sep 28, 2022
1 parent 0ae234e commit dcfff14
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ abstract class CompileStaticGroovyPage extends GroovyPage {

@Override
protected Object lookupTagDispatcher(String namespace) {
gspTagLibraryLookup != null && gspTagLibraryLookup.hasNamespace(namespace)
? new TagLibNamespaceMethodDispatcher(namespace, gspTagLibraryLookup, outputContext) : null
gspTagLibraryLookup?.hasNamespace(namespace) ? new TagLibNamespaceMethodDispatcher(namespace, gspTagLibraryLookup, outputContext) : null
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class GroovyPagesGrailsPlugin extends Plugin {
}

boolean jstlPresent = ClassUtils.isPresent(
"javax.servlet.jsp.jstl.core.Config", InternalResourceViewResolver.class.getClassLoader())
"javax.servlet.jsp.jstl.core.Config", InternalResourceViewResolver.getClassLoader())

abstractViewResolver {
prefix = GrailsApplicationAttributes.PATH_TO_VIEWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class CountryTagLib implements TagLibrary {

// This needs to change, to sort on demand using the BROWSER's locale
static final COUNTRY_CODES_BY_NAME_ORDER =
ISO3166_3.entrySet().sort { a, b -> a.value.compareTo(b.value) }.collect() { it.key }
ISO3166_3.entrySet().sort { a, b -> a.value.compareTo(b.value) }.collect { it.key }
static final COUNTRY_CODES_BY_NAME = new TreeMap()

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
* @attr readonly Makes the resulting inputs and selects to be made read only. Is treated as a Groovy Truth.
*/
Closure datePicker = { attrs ->
def out = out // let x = x ?
def xdefault = attrs['default']
if (xdefault == null) {
xdefault = new Date()
Expand Down Expand Up @@ -797,7 +796,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
}

for (i in 0..23) {
def h = '' + i
def h = i
if (i < 10) {
h = '0' + h
}
Expand Down Expand Up @@ -830,7 +829,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
}

for (i in 0..59) {
def m = '' + i
def m = i
if (i < 10) {
m = '0' + m
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,18 @@ class FormatTagLib implements TagLibrary {
def timeZone = grailsTagDateHelper.getTimeZone(attrs.timeZone)

def dateFormat
if (!type) {
if (type) {
if (type == 'DATE') {
dateFormat = grailsTagDateHelper.getDateFormat(dateStyle, timeZone, locale)
}
else if (type == 'TIME') {
dateFormat = grailsTagDateHelper.getTimeFormat(timeStyle, timeZone, locale)
}
else { // 'both' or 'datetime'
dateFormat = grailsTagDateHelper.getDateTimeFormat(dateStyle, timeStyle, timeZone, locale)
}
}
else {
if (!format && formatName) {
format = messageHelper(formatName, null, null, locale)
if (!format) {
Expand All @@ -194,17 +205,6 @@ class FormatTagLib implements TagLibrary {

dateFormat = grailsTagDateHelper.getFormatFromPattern(format, timeZone, locale)
}
else {
if (type == 'DATE') {
dateFormat = grailsTagDateHelper.getDateFormat(dateStyle, timeZone, locale)
}
else if (type == 'TIME') {
dateFormat = grailsTagDateHelper.getTimeFormat(timeStyle, timeZone, locale)
}
else { // 'both' or 'datetime'
dateFormat = grailsTagDateHelper.getDateTimeFormat(dateStyle, timeStyle, timeZone, locale)
}
}

return grailsTagDateHelper.format(dateFormat, date)
}
Expand Down Expand Up @@ -273,10 +273,7 @@ class FormatTagLib implements TagLibrary {
DecimalFormatSymbols dcfs = locale ? new DecimalFormatSymbols(locale) : new DecimalFormatSymbols()

DecimalFormat decimalFormat
if (!type) {
decimalFormat = new DecimalFormat(format, dcfs)
}
else {
if (type) {
if (type == 'currency') {
decimalFormat = NumberFormat.getCurrencyInstance(locale)
}
Expand All @@ -290,6 +287,9 @@ class FormatTagLib implements TagLibrary {
throwTagError("Attribute [type] of Tag [formatNumber] specifies an unknown type. Known types are currency, number and percent.")
}
}
else {
decimalFormat = new DecimalFormat(format, dcfs)
}

if (attrs.nan) {
dcfs.naN = attrs.nan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ValidationTagLib implements TagLibrary {
}
else if (renderAs.equalsIgnoreCase("xml")) {
def mkp = new MarkupBuilder(out)
mkp.errors() {
mkp.errors {
eachErrorInternal(attrs, {
error(object: it.objectName,
field: it.field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ class SitemeshTagLib implements RequestConstants, TagLibrary {
writer << '>'
}
else {
if (!useXmlClosingForEmptyTag) {
if (useXmlClosingForEmptyTag) {
// XML / XHTML empty tag
writer << '/>'
}
else {
writer << '>'
// in valid HTML , closing of an empty tag depends on the element name
// for empty title, the tag must be closed properly
Expand All @@ -96,15 +100,11 @@ class SitemeshTagLib implements RequestConstants, TagLibrary {
writer << '>'
}
}
else {
// XML / XHTML empty tag
writer << '/>'
}
}
content
}

def StreamCharBuffer wrapContentInBuffer(Object content) {
StreamCharBuffer wrapContentInBuffer(Object content) {
if (content instanceof Closure) {
content = content()
}
Expand All @@ -116,9 +116,7 @@ class SitemeshTagLib implements RequestConstants, TagLibrary {
newbuffer.setPreferSubChunkWhenWritingToOtherBuffer(true)
return newbuffer
}
else {
return (StreamCharBuffer) content
}
return (StreamCharBuffer) content
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ class TagLibraryResolverImpl implements ServletContextAware, GrailsApplicationAw
if (tldReader.tags) {
return new JspTagLibImpl(uri, tldReader.tags, classLoader)
}
else {
return null
}
return null
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.grails.io.support.SpringIOUtils
@CompileStatic
class TldReader {

private static final Log log = LogFactory.getLog(TldReader.class)
private static final Log log = LogFactory.getLog(TldReader)
final Map<String, String> tags = [:]
final List<String> listeners = []
String uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ trait TagLibraryInvoker extends WebAttributes {
// don't add any new metamethod if an existing render method exists, see GRAILS-11581
return !this.respondsTo("render")
}
else {
return true
}
return true
}

/**
Expand Down

0 comments on commit dcfff14

Please sign in to comment.