How can you suppress checkstyle checks within a block of code only for specific rules? [duplicate] - checkstyle

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to disable a particular checkstyle rule for a particular line of code?
In turning off Checkstyle for a segment of code, is there a syntax that would suppress only specific checks.
So rather than just
// CHECKSTYLE:OFF
code
// CHECKSTYLE:ON
you could have something like
// CHECKSTYLE:OFF:RequireThis,
code
// CHECKSTYLE:ON
In cases where we are purposely making an exception to the style, it would be nice to be clearer what the exception case is.

Recommend reading the documentation on SuppressionCommentFilter (it is buried at bit) for lots of examples.
An example of how to do configure the filter is:
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
You can then use the following to turn off the RequireThis check for a block of code:
// CSOFF: RequireThis
... code
// CSON: RequireThis

Related

css commands with arguments

On a website that I am maintaining, I have many code lines like the following one:
<strong>doi</strong>
reference
where "website" is an actual website address and "reference" is a number which depends on each entry of this type (while the website address is always the same). In html/ccs; is it possible to create a command, let's call it doi such that instead of always writing the two lines above, I would equivalently write
<doi>reference</doi>
No it's not possible using just html/css, but it is possible using javascript/jquery or a javascript framework, like angularjs.
Here's an example using jquery:
https://jsfiddle.net/partypete25/31dzyjgL/
<!-- HTML -->
<doi>121</doi>
<!-- JavaScript -->
$("doi").each(function(){
var ref = $(this).text();
$(this).replaceWith( "<strong>doi</strong><a href='http://website/"+ref+"/' target='_blank'>reference</a>" );
});
So the script will look for all of your custom "doi" tags, and replace them with the fleshed out label+link with the dynamic reference.

Issue in windows phone 8 : Error 2 SlideView is not supported in a Silverlight project

I have got few issues while trying to implement a sliding menu ('Facebook' like) in my windows phone 8 application.
When I added the following code in app.xaml, it shows following issues
<Application.RootVisual>
<library:SlideApplicationFrame Header="ManageIT"
Background="White">
<!--<library:SlideApplicationFrame.LeftContent>
<pages:LeftView />
</library:SlideApplicationFrame.LeftContent>-->
<!--<library:SlideApplicationFrame.RightContent>
<pages:RightView />
</library:SlideApplicationFrame.RightContent>-->
</library:SlideApplicationFrame>
</Application.RootVisual>
The exception is given below.
Error 1 Nested properties are not supported: Application.RootVisual.
Error 2 The attachable property 'RootVisual' was not found in type 'Application'.
Error 3 Unexpected PROPERTYELEMENT in parse rule PropertyElement ::= . PROPERTYELEMENT Content? ENDTAG..
Can anyone help me to solve this?
Is it because the reference to System.Windows.UIElement is not done?
Update 1
I have undone the above change and add the following in mainpage.xaml after installing slideview using package manager console
Install-Package SlideView
Here is the code...
<controls:SlideView>
<Grid Background="Teal"
Width="400" />
<Grid Background="Tomato" />
<Grid Background="LightYellow" />
<Grid Background="YellowGreen"
Width="400"/>
</controls:SlideView>
But I have another set of build errors as follows...
Error 1 The namespace prefix "controls" is not defined.
Error 2 SlideView is not supported in a Silverlight project.
Error 3 The namespace prefix "controls" is not defined.
Error 4 The
type 'controls:SlideView' was not found. Verify that you are not
missing an assembly reference and that all referenced assemblies have
been built.
Update 2
Got the above issue fixed, but I have some run time exceptions as following...
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=Operation is not valid due to the current state of the object.
Source=Microsoft.Phone
StackTrace:
at Microsoft.Phone.Controls.PhoneApplicationFrame..ctor()
at slidingmenu.App.InitializePhoneApplication()
at slidingmenu.App..ctor()
InnerException:
Regards
Sebastian
Try to nest your controls in parent control such as StackPanel. Most likely you have messed up the namespaces. What i would do? It will be to compare my code with a working one. CodePlex provides an example source for SlideView. Download it and see what are you missing.
Is the xml namespace defined?
xmlns:controls="clr-namespace:SlideView.Library;assembly=SlideView.Library"
xmlns:slideview3="clr-namespace:slideview3"
If LeftView is one of your controls.
<library:SlideApplicationFrame.LeftContent>
<slideview3:LeftView />
</library:SlideApplicationFrame.LeftContent>
I had the same issue in my (MvvmCross-) app.
I was able to resolve this by creating the RootFrame by code in App.xaml.cs instead of adding it in the Xaml:
private void InitializePhoneApplication()
{
var slideApplicationFrame = new SlideApplicationFrame
{
LeftContent = new LeftView(),
RightContent = new RightView()
};
this.RootFrame = slideApplicationFrame;
this.RootVisual = this.RootFrame;
this.RootFrame.Navigated += this.CompleteInitializePhoneApplication;
// Handle navigation failures
this.RootFrame.NavigationFailed += this.RootFrameNavigationFailed;
}
...and removed the whole <Application.RootVisual>...</Application.RootVisual> in App.xaml.

"text-overflow: ellipsis;" in XUL applications

I'm writing an extension to an existing XUL-application, conkeror. In that, In
some part of the user-interface of I'm writing, I'm creating HTML elements with
a fixed-width, <span>s in this case, to display various results.
Within those spans there's text some text, which, on occasion, is too long to
fit its fixed-with container. I'd like to cut-off the parts that are too long,
and end it with an ellipsis instead.
Those spans currently have the following CSS attributes:
display: inline-block;
width: 30%;
overflow: hidden;
white-space: nowrap;
In addition to that, I'd like to use text-overflow: ellipsis;, but it turns
out the Gecko platform doesn't implement that yet. However, for plain HTML pages
with regular style-sheets, there happens to be a workaround for Firefox and
other Gecko-based products, that makes cutting off overlong text and putting an
ellipsis at its end work anyway.
The details of that technique are described
here. It's
using Gecko's ability to run XUL code to do its magic.
So I've tried to use that in my XUL application as well. I've changed my
style-sheet to include the described
-moz-binding: url('ellipsis.xml#ellipsis');, and also created the
elipsis.xml file as described.
However, doing this (or similar things using different URLs, e.g. chrome:// or
absolute file:// URLs) seems to have no effect whatsoever within my
application. In fact, it doesn't even try to access the ellipsis.xml file at
all, according to strace.
Obviously XUL is able to do what I want, so I'm assuming I'm doing something
wrong, or am simply missing out on some detail I have to take care of first in
order to get the desired results.
What I'm looking for is a way to pull the regular text-overflow: ellipsis;
track within a XUL application or, alternatively, a way to get the same result
without the aforementioned technique.
For some (maybe security) reason you need to use a chrome:// url in your CSS file. I tested it with conkeror 0.9.2 and xulrunner 1.9.1.
-moz-binding: url("chrome://conkeror/content/ellipsis.xml#ellipsis");
Where your ellipsis.xml is in /conkeror/install/path/modules/ (on debian /usr/share/conkeror/modules). You can check the chrome.manifest file to find the right location for your XML file, probably the style folder.
You said it´s not having ANY effect?
With
display:block; text-overflow:clip; overflow:hidden; white-space:nowrap;
it should at least cut off the text without the "...".
Is the reference to your xml file correct and your css and xml files are at the same path?
Also, try using this code:
<?xml version="1.0"?>
<bindings
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
>
<binding id="none">
<content><children/></content>
</binding>
<binding id="ellipsis">
<content>
<xul:label crop="end"><children/></xul:label>
</content>
<implementation>
<field name="label"> document.getAnonymousNodes( this )[ 0 ] </field>
<field name="style"> this.label.style </field>
<property name="display">
<getter>
this.style.display
</getter>
<setter>
if( this.style.display != val ) this.style.display= val
</setter>
</property>
<property name="value">
<getter>
this.label.value
</getter>
<setter>
if( this.label.value != val ) this.label.value= val
</setter>
</property>
<method name="update">
<body>
var strings= this.textContent.split( /\s+/g )
if( !strings[ 0 ] ) strings.shift()
if( !strings[ strings.length - 1 ] ) strings.pop()
this.value= strings.join( ' ' )
this.display= strings.length ? '' : 'none'
</body>
</method>
<constructor> this.update() </constructor>
</implementation>
<handlers>
<handler event="DOMSubtreeModified"> this.update() </handler>
</handlers>
</binding>
</bindings>

Naming "class" and "id" HTML attributes - dashes vs. underlines [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
<div id="example-value"> or <div id="example_value">?
This site and Twitter use the first style. Facebook and Vimeo - the second.
Which one do you use and why?
Use Hyphens to ensure isolation between your HTML and JavaScript.
Why? see below.
Hyphens are valid to use in CSS and HTML but not for JavaScript Objects.
A lot of browsers register HTML Ids as global objects on the window/document object, in big projects, this can become a real pain.
For this reason, I use names with Hyphens this way the HTML ids will never conflict with my JavaScript.
Consider the following:
message.js
message = function(containerObject){
this.htmlObject = containerObject;
};
message.prototype.write = function(text){
this.htmlObject.innerHTML+=text;
};
html
<body>
<span id='message'></span>
</body>
<script>
var objectContainer = {};
if(typeof message == 'undefined'){
var asyncScript = document.createElement('script');
asyncScript.onload = function(){
objectContainer.messageClass = new message(document.getElementById('message'));
objectContainer.messageClass.write('loaded');
}
asyncScript.src = 'message.js';
document.appendChild(asyncScript);
}else{
objectContainer.messageClass = new message(document.getElementById('message'));
objectContainer.messageClass.write('loaded');
}
</script>
If the browser registers HTML ids as global objects the above will fail because the message is not 'undefined' and it will try to create an instance of the HTML object. By making sure an HTML id has a hyphen in the name prevents conflicts like the one below:
message.js
message = function(containerObject){
this.htmlObject = containerObject;
};
message.prototype.write = function(text){
this.htmlObject.innerHTML+=text;
};
html
<body>
<span id='message-text'></span>
</body>
<script>
var objectContainer = {};
if(typeof message == 'undefined'){
var asyncScript = document.createElement('script');
asyncScript.onload = function(){
objectContainer.messageClass = new message(document.getElementById('message-text'));
objectContainer.messageClass.write('loaded');
}
asyncScript.src = 'message.js';
document.appendChild(asyncScript);
}else{
objectContainer.messageClass = new message(document.getElementById('message-text'));
objectContainer.messageClass.write('loaded');
}
</script>
Of course, you could use messageText or message_text but this doesn't solve the problem and you could run into the same issue later where you would accidentally access an HTML Object instead of a JavaScript one
One remark, you can still access the HTML objects through the (for example) window object by using window['message-text'];
I would recommend the Google HTML/CSS Style Guide
It specifically states:
Separate words in ID and class names by a hyphen. Do not concatenate words and abbreviations in selectors by any characters (including none at all) other than hyphens, in order to improve understanding and scannability.
/* Not recommended: does not separate the words “demo” and “image” */
.demoimage {}
/* Not recommended: uses underscore instead of hyphen */
.error_status {}
/* Recommended */
#video-id {}
.ads-sample {}
It really comes down to preference, but what will sway you in a particular direction might be the editor you code with. For instance, the auto-complete feature of TextMate stops at a hyphen, but sees words separated by an underscore as a single word. So class names and ids with the_post work better than the-post when using its auto-complete feature (Esc).
I believe this is entirely up to the programmer. You could use camelCase too if you wanted (but I think that would look awkward.)
I personally prefer the hyphen, because it is quicker to type on my keyboard. So I would say that you should go with what you are most comfortable with, since both your examples are widely used.
Either example is perfectly valid, you can even throw into the mix ":" or "." as separators according to the w3c spec. I personally use "_" if it is a two word name just because of its similarity to space.
I use the first one (one-two) because its more readable. For images though I prefer the underscore (btn_more.png). Camel Case (oneTwo) is another option.
Actually some external frameworks (javascript, php) have difficulties (bugs?) with using the hypen in id names. I use underscore (so does 960grid) and all works great.
I would suggest underscore mainly for the reason of a javascript side-effect I'm encountering.
If you were to type the code below into your location bar, you would get an error: 'example-value' is undefined. If the div were named with underscores, it would work.
javascript:alert(example-value.currentStyle.hasLayout);

How to parse an .as (AS3) file

I am looking to get as close as I can to parsing out an AS3 file into objects or XML. For instance, imagine the following class:
package {
class SomeClass extends AnotherClass {
private var someVariable:Number
public function someMethod(someParameter:Number = 4):void {
var someLocalVariable:Number = someParameter * (2 + someVariable);
}
}
}
When parsed, it might be something like:
<package name="">
<class id="783" name="SomeClass" extendsId="782">
<variable id="784" visibility="private" type="Number"/>
<function id="785" name="someMethod" returnType="void">
<parameter id="786" name="someParameter" type="Number">
<expression>
<number value="4"/>
</expression>
</parameter>
<variable id="787" name="someLocalVariable" type="Number"/>
<code>
<assign toId="787">
<expression>
<variable id="786"/>
<operator type="*"/>
<expression>
<number value="2"/>
<operator type="+"/>
<variable id="786"/>
</expression>
</expression>
</assign>
</code>
</function>
</class>
</package>
.. even if I don't get a nice, neat xml structure like this, even if it could just parse AS3 to some kind of capacity, it would be way beyond where I am now.
Any thoughts?
Thanks,
Eric
I have actually ported the PMD parser to AS3.
You can check out http://github.com/teotigraphix/as3parser-framework
Mike
FlexPMD has an as3 parser. (FlexPMD is a Java project by Adobe that does reporting of best practices violations in as3 source code.)
FlexPMD is hosted at http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD
The code is on a subversion repo at http://opensource.adobe.com/svn/opensource/flexpmd/trunk
The down side is you would need to use Maven to build FlexPMD (me, I never managed to get it to work), but since you need just one or three projects, it might be possible to extract those by hand without too much cursing and shouting.
You may also want to wander further into the Flex SDK source code (also on opensource.adobe.com) to see if Adobe provides any other software for parsing as3,but I have not looked there.
There's a lexer, parser, and tokenizer in the AS3eval project:
AS3eval
Take a look at the flash.utils.describeType() documentation.
http://livedocs.adobe.com/flex/gumbo/langref/flash/utils/package.html#describeType()
It's for describe actionscript items at runtime, but should have some use in this case.