You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/08/08 19:53:33 UTC

[GitHub] [netbeans] Chris2011 opened a new pull request, #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Chris2011 opened a new pull request, #4485:
URL: https://github.com/apache/netbeans/pull/4485

   This PR adds a new HTML Rule, Hint and HintFix for a missing "alt" attribute for following tags: img, applet, area.
   
   I copied over some code from existing ExtractInlinedStyleRule and ExtractInlinedStyleHint and checked it, how it works. Fun fact, atm ExtractInlinedStyleHintFix is not working atm, it will throw an NPE, but this is not broken due to my changes. I will try to fix this later, in a seperate PR. Please have a look into the code. I will handle this as a draft and I will change some things like to add the rule/hint to the layers.xml instead of the HtmlHintsProvider as mentioned in the comment.
   
   Also I changed a private method which gives you the exact offset of the tag <tag> or <img /> problem here is that I need to add the attribute before the closing token so I added a bool to change this behaviour just for my and future needs. The rest is still working as before.
   
   I also try to add tests for the hint, but there are atm no tests at all.
   
   I also notied the extra space before my " alt=\"\"" when it is a closing tag. I can also try to fix this to check for token WS but it is the same behaviour as for WebStorm. It is better than nothing IMHO.
   
   ![insert-alt-attribute](https://user-images.githubusercontent.com/795658/183502609-b63e5aca-3460-4fbb-9fd0-f2f999c4a8fa.gif)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1162277506


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Chris
+ */
+public class HtmlTagContextUtils {

Review Comment:
   `public final class`.
   Please add a private constructor.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303751096


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+            AddMissingAltAttributeRule.SINGLETON.getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(() -> {
+                try {
+                    Source source = Source.create(context.getFile());
+                    OffsetRange adjustContextRange = HtmlTagContextUtils.adjustContextRange(source.getDocument(false), range.getStart(), range.getEnd(), true);
+
+                    source.getDocument(false).insertString(adjustContextRange.getEnd(), " alt=\"\"", null);
+                } catch (BadLocationException ex) {
+                    Exceptions.printStackTrace(ex);

Review Comment:
   Instead, I would add a log.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303752040


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AltAttributeVisitor.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.*;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AltAttributeVisitor implements ElementVisitor {
+    private static final String ALT_ATTR = "alt";

Review Comment:
   `// NOI18N`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1214175891

   > I left a few inline comments, but I made a general observation, that the integration looks a bit strange right now:
   > 
   > ![image](https://user-images.githubusercontent.com/2179736/183994346-6de71823-7850-4201-b852-32c0995c9fc7.png)
   > 
   > As you can see, I get an error indicator for the img-Tag, but I don't get the fixes. To get these I have to click inside the range of img-Tag:
   > 
   > ![image](https://user-images.githubusercontent.com/2179736/183994861-9416398f-f742-4eff-b2cc-fc92b55b443b.png)
   > 
   > I think this should be made consistent.
   
   You are right and I already tried a bit but the offset and searching logic for tokens (Tag open, tag open symbol, tag closing, etc.) drives me crazy. Will try to fix this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] mbien commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
mbien commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r941150401


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttribute/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other.AddMissingAltAttribute;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Chris
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(RuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+                AddMissingAltAttributeRule.SINGLETON.getDisplayName(),
+                context.parserResult.getSnapshot().getSource().getFileObject(),
+                range,
+                Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context)),
+                10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        RuleContext context;
+
+        public AddMissingAltAttributeHintFix(RuleContext context) {
+            this.context = context;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(new Runnable() {
+
+                @Override
+                public void run() {

Review Comment:
   feel free to bump the language level to 1.8 so that you can use lambdas.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1502254286

   @Chris2011 NB18 is coming nearer. Shall this stay on the NB18 milestone, then an update would be good now (branch happens in 8 days) or moving to NB 19 should be considered.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r942785043


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java:
##########
@@ -166,6 +166,7 @@ public void computeSuggestions(HintsManager manager, RuleContext context, List<H
         if(ExtractInlinedStyleRule.SINGLETON.appliesTo(context)) {
             suggestions.add(new ExtractInlinedStyleHint(context, new OffsetRange(context.caretOffset, context.caretOffset)));
         }
+

Review Comment:
   This white-space change should not be here.



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        Project project = FileOwnerQuery.getOwner(file);
+
+        if (project == null) {
+            return false;
+        }

Review Comment:
   Why is the project checked - it is not used later. This results in this:
   
   ![image](https://user-images.githubusercontent.com/2179736/183995129-691d1d7c-1e6e-4c41-872d-052cec39e84a.png)
   
   The cursor is in the img-Tag (see my general comment), I get the error indicator, but I don't get the fix.



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }

Review Comment:
   Why is the file checked - it is not used.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1503896458

   Removed the NB18 milestone and converted this to draft.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1510356824


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;

Review Comment:
   Unnecessary import



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;

Review Comment:
   Unnecessary import



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.getInstance(),
+            AddMissingAltAttributeRule.getInstance().getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        private static final Logger LOGGER = Logger.getLogger(AddMissingAltAttributeHintFix.class.getSimpleName());
+
+        HtmlRuleContext context;
+        OffsetRange range;

Review Comment:
   These can be `private` and `final`



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.getInstance(),
+            AddMissingAltAttributeRule.getInstance().getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        private static final Logger LOGGER = Logger.getLogger(AddMissingAltAttributeHintFix.class.getSimpleName());
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.getInstance().getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            BaseDocument document = (BaseDocument) context.getSnapshot().getSource().getDocument(true);
+            document.runAtomic(() -> {
+                try {
+                    OffsetRange adjustedRange = HtmlTagContextUtils.adjustContextRange(document, range.getStart(), range.getEnd(), true);
+                    String tagContent = document.getText(adjustedRange.getStart(), adjustedRange.getLength());
+
+                    // Find last self-closing or non self-closing tag
+                    Pattern closingTagPattern = Pattern.compile("(/?>)");
+                    Matcher closingTagMatcher = closingTagPattern.matcher(tagContent);
+
+                    if (closingTagMatcher.find()) {
+                        int altInsertPosition = adjustedRange.getStart() + closingTagMatcher.start(1);

Review Comment:
   This might lead to wrong results. Consider PHP with embedded HTML. The document could look like this:
   
   ```php
   <img src='demo.png' alt='<?php echo htmlspecialchars('x > y');?>' />
   ```
   
   I would use the HTML token stream and either use the start of the closing token or, if that does not exist, the start of the last HTML token + length.



##########
ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java:
##########
@@ -4384,8 +4384,11 @@ protected ComputedHints computeHints(final NbTestCase test, final Rule hint, Str
                             }
                         }
                         if (HintsSettings.getSeverity(manager, ucr) == HintSeverity.CURRENT_LINE_WARNING) {
-                            manager.setTestingRules(null, Collections.EMPTY_MAP, testHints, null);
+                            manager.setTestingRules(null, testHints, testHints, null);
                             provider.computeSuggestions(manager, context, hints, caretOffset);
+                        } else if(HintsSettings.getSeverity(manager, ucr) == HintSeverity.ERROR || HintsSettings.getSeverity(manager, ucr) == HintSeverity.WARNING) {
+                            manager.setTestingRules(null, testHints, testHints, null);
+                            provider.computeErrors(manager, context, hints, new ArrayList<Error>());

Review Comment:
   Did you test, that all current tests invoking `computeHints`, potentially transitively, still work?



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;

Review Comment:
   Unnecessary import



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1209830835

   Now I removed the rule and hint from the HintsProvider and add it to the layer.xml. The new rule extends now HtmlRule and runs the Hint by itself.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1927934974

   > My gut feeling is, that the HtmlHintsProvider and the expectations of the CslTestBase/GsfHintsManager don't match. It seems suggestions were never really supported. It might be worthy looking into JS/CSS whether there are suggestions being checked. I'm not sure, that modifying CslTestBase is really a good idea.
   
   Hey @matthiasblaesing thx for your info and hint. I'm definitely with you, I will check the JS stuff, because CSS has also no real hints/fixes (just basic stuff) as I have. I also thought that this was never tried before. Lemme check more what I can do.
   
   For the invokeLater, thx for the hint with the change, I got this from ExtractInlinedStyleHint but due to I not doing extrem things like opening a new UI, it is not needed here. I just add stuff into the editor.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1511741132


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;

Review Comment:
   You mean, they are unnecessary, when I change the logik, right? Because atm I need them.



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;

Review Comment:
   Same as above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1511784108


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;

Review Comment:
   Neither `Document`, nor `Source` are used. I admit, that I only noticed that because NetBeans marked these:
   
   ![image](https://github.com/apache/netbeans/assets/2179736/e2e15835-0748-411c-8b16-515e8580b786)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r943932355


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlHintsProvider.java:
##########
@@ -166,6 +166,7 @@ public void computeSuggestions(HintsManager manager, RuleContext context, List<H
         if(ExtractInlinedStyleRule.SINGLETON.appliesTo(context)) {
             suggestions.add(new ExtractInlinedStyleHint(context, new OffsetRange(context.caretOffset, context.caretOffset)));
         }
+

Review Comment:
   Just a leftover after I removed my check. Will remove it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303762946


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class HtmlTagContextUtils {
+    private HtmlTagContextUtils() {
+    }
+
+    public static OffsetRange adjustContextRange(final Document doc, final int from, final int to, final boolean beforeClosingToken) {
+        final AtomicReference<OffsetRange> ret = new AtomicReference<>();
+        ret.set(new OffsetRange(from, to)); //return the same pair by default
+        doc.render(() -> {
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(doc, from);
+
+            if (ts == null) {
+                //no html token sequence at the offset, try to
+                //TODO possibly try to travese the top level sequence backward
+                //and try to find an html embedding.
+                return;
+            }
+
+            Token<HTMLTokenId> openTag = Utils.findTagOpenToken(ts);
+
+            if (openTag == null) {
+                return;
+            }
+
+            int adjustedFrom = ts.offset();
+
+            //now try to find the tag's end
+            ts.move(to);
+            int adjustedTo = -1;
+            while (ts.moveNext()) {
+                Token<HTMLTokenId> t = ts.token();

Review Comment:
   Need `null` Check



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1691080174

   > Please write an example code to verify this in the description.
   > 
   > Please add unit tests. (`CslTestBase` has `checkHints()` and `applyHint()`)
   
   Thx, I was searching for this. Will check it out.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1304950120


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.List;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.ElementType;
+import org.netbeans.modules.html.editor.lib.api.elements.ElementUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean showInTasklist() {
+        return true;
+    }
+
+    @Override
+    public HintSeverity getDefaultSeverity() {
+        return HintSeverity.CURRENT_LINE_WARNING;
+    }
+
+    @Override
+    protected void run(HtmlRuleContext context, List<Hint> result) {
+        try {
+            HtmlParserResult parserResult = context.getHtmlParserResult();
+            AltAttributeVisitor visitor = new AltAttributeVisitor(this, context, result, "img|applet|area");

Review Comment:
   `// NOI18N`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1304950018


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.List;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.ElementType;
+import org.netbeans.modules.html.editor.lib.api.elements.ElementUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();

Review Comment:
   ```suggestion
       private static AddMissingAltAttributeRule INSTANCE = new AddMissingAltAttributeRule();
       
       private AddMissingAltAttributeRule() {
       }
       
       public static AddMissingAltAttributeRule getInstance() {
           return INSTANCE;
       }
   ```
   BTW, Please note that we have to make it thread-safe if we make this class singleton.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1356890452

   @matthiasblaesing I think I got it now :). I did the pull and rebase from within NetBeans and it had some conflicts, that I thought I fixed them but unfortunately not correct, sry for that. I reset everything to my last commit.
   
   So now we can focus again on the initial task.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1052611390


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Chris

Review Comment:
   I suggest to either replace this with something more distinctive (there are multiple instances of Chris) or remove it (history holds the full author information).



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        Project project = FileOwnerQuery.getOwner(file);
+
+        if (project == null) {
+            return false;
+        }
+
+        Document doc = context.parserResult.getSnapshot().getSource().getDocument(true);
+
+        if (doc == null) {
+            return false;
+        }
+
+        return isAltAttributeRequiredAndMissing(doc, new OffsetRange(context.caretOffset, context.caretOffset));
+    }
+
+    @Override
+    public String getDisplayName() {
+        return Bundle.AddMissingAltAttributeRuleName();
+    }
+
+    @Override
+    public boolean showInTasklist() {
+        return false;
+    }
+
+    @Override
+    public HintSeverity getDefaultSeverity() {
+        return HintSeverity.CURRENT_LINE_WARNING;
+    }
+
+    @Override
+    protected void run(HtmlRuleContext context, List<Hint> result) {
+        result.add(new AddMissingAltAttributeHint(this.context, new OffsetRange(this.context.caretOffset, this.context.caretOffset)));
+    }
+
+    private boolean isAltAttributeRequiredAndMissing(Document doc, OffsetRange range) {
+        OffsetRange adjusted = HtmlTagContextUtils.adjustContextRange(doc, range.getStart(), range.getEnd(), false);
+
+        return AddMissingAltAttributeRule.isAltAttributeRequired(doc, adjusted.getStart(), adjusted.getEnd()) && !AddMissingAltAttributeRule.isAltAttributeAvailable(doc, adjusted.getStart(), adjusted.getEnd());
+    }
+
+    private static boolean isAltAttributeRequired(final Document doc, final int from, final int to) {
+        final AtomicReference<List<Boolean>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<Boolean> found = new LinkedList<>();
+            result.set(found);
+            
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, from);
+            
+            if (ts == null) {
+                //XXX - try to search backward and forward to find some html code???
+                return;
+            }
+            
+            //the joined ts is moved to the from offset and a token already selected (moveNext/Previous() == true)
+            //seek for all tag's attributes with css embedding representing an inlined style
+            String tag = null;
+            
+            do {
+                Token<HTMLTokenId> t = ts.token();
+                if (t.id() == HTMLTokenId.TAG_OPEN && t.text().toString().matches("img|applet|area")) {
+                    tag = t.text().toString();
+                } else if (t.id() == HTMLTokenId.TAG_CLOSE_SYMBOL) {
+                    //closing tag, produce the info
+                    if (tag != null) {
+                        // no alt tag found but required tag
+                        found.add(true);
+                        tag = null;
+                    }
+                }
+            } while (ts.moveNext() && ts.offset() <= to);
+        });
+
+        return !result.get().isEmpty();
+    }
+
+    private static boolean isAltAttributeAvailable(final Document doc, final int from, final int to) {
+        final AtomicReference<List<InlinedStyleInfo>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<InlinedStyleInfo> found = new LinkedList<>();
+            result.set(found);
+            
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, from);
+            
+            if (ts == null) {
+                //XXX - try to search backward and forward to find some html code???
+                return;
+            }
+            
+            //the joined ts is moved to the from offset and a token already selected (moveNext/Previous() == true)
+            //seek for all tag's attributes with css embedding representing an inlined style

Review Comment:
   This looks to complex to find the alt Attribute.  The variables here indicate extraction of class, alt, id - is this copied from somewhere else?



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")

Review Comment:
   This message key should be `AddMissingAltAttributeRule` - you can then drop the implementation of `getDisplayName` as the superclass already implements it:
   
   https://github.com/apache/netbeans/blob/a8edf3bf92e38ac22a83e24ec910f29094f0fee3/ide/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlRule.java#L86-L89
   with
   https://github.com/apache/netbeans/blob/a8edf3bf92e38ac22a83e24ec910f29094f0fee3/ide/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlRule.java#L60-L63
   
   You also need to define a message named `AddMissingAltAttributeRule_Desc` (you get an exception when you click on the hint in the option panel):
   
   https://github.com/apache/netbeans/blob/a8edf3bf92e38ac22a83e24ec910f29094f0fee3/ide/html.editor/src/org/netbeans/modules/html/editor/hints/HtmlRule.java#L65-L68
   
   I suggest to use : `Provide Text Alternatives` for the display name (to get it more in line with the rest of the entries) and `Find img/applet/area elements where no alt attribute is provided.` (for the description)
   
   ![image](https://user-images.githubusercontent.com/2179736/208514700-8d7ab9fe-ea80-4fe2-a993-74aea0cbb743.png)
   



##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        Project project = FileOwnerQuery.getOwner(file);
+
+        if (project == null) {
+            return false;
+        }
+
+        Document doc = context.parserResult.getSnapshot().getSource().getDocument(true);
+
+        if (doc == null) {
+            return false;
+        }
+
+        return isAltAttributeRequiredAndMissing(doc, new OffsetRange(context.caretOffset, context.caretOffset));
+    }
+
+    @Override
+    public String getDisplayName() {
+        return Bundle.AddMissingAltAttributeRuleName();
+    }
+
+    @Override
+    public boolean showInTasklist() {
+        return false;
+    }
+
+    @Override
+    public HintSeverity getDefaultSeverity() {
+        return HintSeverity.CURRENT_LINE_WARNING;
+    }
+
+    @Override
+    protected void run(HtmlRuleContext context, List<Hint> result) {
+        result.add(new AddMissingAltAttributeHint(this.context, new OffsetRange(this.context.caretOffset, this.context.caretOffset)));
+    }
+
+    private boolean isAltAttributeRequiredAndMissing(Document doc, OffsetRange range) {
+        OffsetRange adjusted = HtmlTagContextUtils.adjustContextRange(doc, range.getStart(), range.getEnd(), false);
+
+        return AddMissingAltAttributeRule.isAltAttributeRequired(doc, adjusted.getStart(), adjusted.getEnd()) && !AddMissingAltAttributeRule.isAltAttributeAvailable(doc, adjusted.getStart(), adjusted.getEnd());
+    }
+
+    private static boolean isAltAttributeRequired(final Document doc, final int from, final int to) {
+        final AtomicReference<List<Boolean>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<Boolean> found = new LinkedList<>();
+            result.set(found);
+            
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, from);
+            
+            if (ts == null) {
+                //XXX - try to search backward and forward to find some html code???
+                return;
+            }
+            
+            //the joined ts is moved to the from offset and a token already selected (moveNext/Previous() == true)
+            //seek for all tag's attributes with css embedding representing an inlined style

Review Comment:
   this comment looks as if it does not match.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1304941579


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+            AddMissingAltAttributeRule.SINGLETON.getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        private static final Logger LOGGER = Logger.getLogger(AddMissingAltAttributeHintFix.class.getSimpleName());
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(() -> {
+                try {
+                    Source source = Source.create(context.getFile());
+                    OffsetRange adjustContextRange = HtmlTagContextUtils.adjustContextRange(source.getDocument(false), range.getStart(), range.getEnd(), true);
+
+                    source.getDocument(false).insertString(adjustContextRange.getEnd(), " alt=\"\"", null); // NOI18N
+                } catch (BadLocationException ex) {
+                    LOGGER.log(Level.SEVERE, ex.getMessage());

Review Comment:
   ```suggestion
                       LOGGER.log(Level.WARNING, "Invalid offset: {0}", ex.offsetRequested()); // NOI18N
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1502894194

   > @Chris2011 NB18 is coming nearer. Shall this stay on the NB18 milestone, then an update would be good now (branch happens in 8 days) or moving to NB 19 should be considered.
   
   We should remove the label completely. I have one bug there when it is a warning instead of a suggestion and I need to figure that out first. I had a look into my other PRs and I wanted to focus on another one first. Step by step.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1304941579


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+            AddMissingAltAttributeRule.SINGLETON.getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        private static final Logger LOGGER = Logger.getLogger(AddMissingAltAttributeHintFix.class.getSimpleName());
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(() -> {
+                try {
+                    Source source = Source.create(context.getFile());
+                    OffsetRange adjustContextRange = HtmlTagContextUtils.adjustContextRange(source.getDocument(false), range.getStart(), range.getEnd(), true);
+
+                    source.getDocument(false).insertString(adjustContextRange.getEnd(), " alt=\"\"", null); // NOI18N
+                } catch (BadLocationException ex) {
+                    LOGGER.log(Level.SEVERE, ex.getMessage());

Review Comment:
   ```suggestion
                       LOGGER.log(Level.WARNING, "Invalid offset: {0}", ex.offsetRequested());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1692330606

   Tests still missing, I'm on it. Thx for all the information.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1912662821

   It is still in draft mode but can please someone have a look into my test impl? @junichi11 or @matthiasblaesing. For checkHints I needed to make a change in the CslTestBase but I'm not 100% sure whether I needed to do this or not. w/o my change the problem was that the hint was never triggered due to not writing the correct property for hints/suggestions (L4387: https://github.com/apache/netbeans/pull/4485/files#diff-afbe604d62e2e9bec89e4ed0e712ad047106ed77e63c2c4030e76a54d762941fR4387).
   
   For the applyHint test, I also needed to change code within the CslTestBase in the method findApplicableFix (L4624: https://github.com/apache/netbeans/pull/4485/files#diff-afbe604d62e2e9bec89e4ed0e712ad047106ed77e63c2c4030e76a54d762941fR4624) from text == null to text != null. I'm also not 100% sure but the code makes more sense for me now. Otherwise it will always return null which breaks the code in applyHint (assertNotNull(fix))- This test is also funny, often it fails with that the expectation of the result is not the correct one but when I debug 1min or so with F8 to jump over the code, etc. it says that the test is green and I don't know what's wrong here.
   
   I also added a check for Error and Warning which was missing, because if Current_line_warning is false it is not that the rest is always an error or an warning. computeHints maybe is missnamed here. It will just check for html version, nothing else. So all in all the code is often very frustrating to check and I needed days for debugging and yes it could be that I don't understand the code 100% that's why I'm asking for a bit of help please. Thanks all.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1211625846

   > > Do I need to worry about the failing travis stuff? A quick look seems not related to my stuff anyway.
   > 
   > I just restarted them. Looks good so far. You don't have a restart button?
   
   I had, but I didn't want to create some noice. But next time, I will try this first :). Thx for the info.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1356796053

   @matthiasblaesing thx for the info, will have a look soon.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1339983996

   @matthiasblaesing after long thinking about this again I would disagree with the consistency. The warning/error/hint is really for the tag as you also see that the tag is highlighted when a div is around. So the hint shows it exactly for line + columnStart + columnEnd. For example if you have this example:
   
   `<div><img src="" /></div>`
   
   I really don't want to have the fix inside the div which is correct on this position. So the fix should really inside of the img tag not everywhere else.
   
   Maybe the problem here is that the hint on the sidebar has an other expectation for the user.
   
   Here are some other things:
   * I checked the HTML validator it also selects the img tag, I mean you have all the information from that.
   * I checked VS Code. They have no light bulb hardcoded on the sidebar so they just underline the img tag. The light bulb comes up when I set the cursor after `<|`.
   * I checked WebStorm, it treats the missing alt attribute also as warning, but they don't show the warning as a light bulb and I also can't switch this. The light bulb also appears just after I set the cursor on `<|`.
   
   So all in all, I think how NetBeans treats and shows warnings, is not optimal but this is not what I want to fix here. I also changed from warning to suggestion on current line, but the problem here is the highlight disappears too and the "suggestion"  is just seen in the statusbar BUT it just appears also on the img, not on the whitespace tokens before the tag_open_symbol. Hope that explains a bit more. I will just fix also a multi line img which makes sense to have the fix there too but not for the whole line. This will be a hole new topic IMHO.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1359534507

   @matthiasblaesing thx for your hints, will fix them :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1690960756

   Please write an example code to verify this in the description.
   
   Please add unit tests. (`CslTestBase` has `checkHints()` and `applyHint()`)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1699749022

   Thx for your review @matthiasblaesing. Yes I already encountered the missing xml part but this was done by a merge because I already had it. So I changed this now back to draft, because I already created the first test but it is still red due to not triggering the warning/suggestion handled as a error. After this I will change this back to normal.
   
   Also I will have a look into the part that you wrote with the visit method change and the new added empty space. Thx.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r941761102


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttribute/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other.AddMissingAltAttribute;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Chris
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(RuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+                AddMissingAltAttributeRule.SINGLETON.getDisplayName(),
+                context.parserResult.getSnapshot().getSource().getFileObject(),
+                range,
+                Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context)),
+                10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        RuleContext context;
+
+        public AddMissingAltAttributeHintFix(RuleContext context) {
+            this.context = context;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(new Runnable() {
+
+                @Override
+                public void run() {

Review Comment:
   did it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1210249481

   Do I need to worry about the failing travis stuff? A quick look seems not related to my stuff anyway.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] mbien commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
mbien commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1210551624

   > Do I need to worry about the failing travis stuff? A quick look seems not related to my stuff anyway.
   
   I just restarted them. Looks good so far. You don't have a restart button?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r943932641


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        Project project = FileOwnerQuery.getOwner(file);
+
+        if (project == null) {
+            return false;
+        }

Review Comment:
   Thx for the hint, yeah I didn't test an HTML file w/o having a project :).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1358324105

   > I left a few inline comments, but I made a general observation, that the integration looks a bit strange right now:
   > 
   > ![image](https://user-images.githubusercontent.com/2179736/183994346-6de71823-7850-4201-b852-32c0995c9fc7.png)
   > 
   > As you can see, I get an error indicator for the img-Tag, but I don't get the fixes. To get these I have to click inside the range of img-Tag:
   > 
   > ![image](https://user-images.githubusercontent.com/2179736/183994861-9416398f-f742-4eff-b2cc-fc92b55b443b.png)
   > 
   > I think this should be made consistent.
   
   This can be ignored, as there are two hints/rules active here:
   
   - the HTML validator marks the whole element as error
   - your new rule, which indeed only applies for the elements
   
   When I deactivate the corresponding "All Other" category, I get the desired behavior, so is ok.
   
   ![image](https://user-images.githubusercontent.com/2179736/208520383-c2acc0fd-b47c-4766-b320-70456bbec55a.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303761652


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class HtmlTagContextUtils {

Review Comment:
   Please add `final`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1054805499


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeRule.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintSeverity;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult;
+import org.netbeans.modules.html.editor.hints.HtmlRule;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.web.common.api.WebUtils;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author Chris
+ */
+@NbBundle.Messages("AddMissingAltAttributeRuleName=Insert required 'alt' attribute")
+public class AddMissingAltAttributeRule extends HtmlRule {
+
+    public static AddMissingAltAttributeRule SINGLETON = new AddMissingAltAttributeRule();
+    private RuleContext context;
+
+    @Override
+    public boolean appliesTo(RuleContext context) {
+        this.context = context;
+
+        HtmlParserResult result = (HtmlParserResult) context.parserResult;
+        FileObject file = result.getSnapshot().getSource().getFileObject();
+
+        if (file == null) {
+            return false;
+        }
+
+        Project project = FileOwnerQuery.getOwner(file);
+
+        if (project == null) {
+            return false;
+        }
+
+        Document doc = context.parserResult.getSnapshot().getSource().getDocument(true);
+
+        if (doc == null) {
+            return false;
+        }
+
+        return isAltAttributeRequiredAndMissing(doc, new OffsetRange(context.caretOffset, context.caretOffset));
+    }
+
+    @Override
+    public String getDisplayName() {
+        return Bundle.AddMissingAltAttributeRuleName();
+    }
+
+    @Override
+    public boolean showInTasklist() {
+        return false;
+    }
+
+    @Override
+    public HintSeverity getDefaultSeverity() {
+        return HintSeverity.CURRENT_LINE_WARNING;
+    }
+
+    @Override
+    protected void run(HtmlRuleContext context, List<Hint> result) {
+        result.add(new AddMissingAltAttributeHint(this.context, new OffsetRange(this.context.caretOffset, this.context.caretOffset)));
+    }
+
+    private boolean isAltAttributeRequiredAndMissing(Document doc, OffsetRange range) {
+        OffsetRange adjusted = HtmlTagContextUtils.adjustContextRange(doc, range.getStart(), range.getEnd(), false);
+
+        return AddMissingAltAttributeRule.isAltAttributeRequired(doc, adjusted.getStart(), adjusted.getEnd()) && !AddMissingAltAttributeRule.isAltAttributeAvailable(doc, adjusted.getStart(), adjusted.getEnd());
+    }
+
+    private static boolean isAltAttributeRequired(final Document doc, final int from, final int to) {
+        final AtomicReference<List<Boolean>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<Boolean> found = new LinkedList<>();
+            result.set(found);
+            
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, from);
+            
+            if (ts == null) {
+                //XXX - try to search backward and forward to find some html code???
+                return;
+            }
+            
+            //the joined ts is moved to the from offset and a token already selected (moveNext/Previous() == true)
+            //seek for all tag's attributes with css embedding representing an inlined style
+            String tag = null;
+            
+            do {
+                Token<HTMLTokenId> t = ts.token();
+                if (t.id() == HTMLTokenId.TAG_OPEN && t.text().toString().matches("img|applet|area")) {
+                    tag = t.text().toString();
+                } else if (t.id() == HTMLTokenId.TAG_CLOSE_SYMBOL) {
+                    //closing tag, produce the info
+                    if (tag != null) {
+                        // no alt tag found but required tag
+                        found.add(true);
+                        tag = null;
+                    }
+                }
+            } while (ts.moveNext() && ts.offset() <= to);
+        });
+
+        return !result.get().isEmpty();
+    }
+
+    private static boolean isAltAttributeAvailable(final Document doc, final int from, final int to) {
+        final AtomicReference<List<InlinedStyleInfo>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<InlinedStyleInfo> found = new LinkedList<>();
+            result.set(found);
+            
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, from);
+            
+            if (ts == null) {
+                //XXX - try to search backward and forward to find some html code???
+                return;
+            }
+            
+            //the joined ts is moved to the from offset and a token already selected (moveNext/Previous() == true)
+            //seek for all tag's attributes with css embedding representing an inlined style

Review Comment:
   Yes, also as you can see the comments, it was copied from the method findInlineStyle of class ExtractInlinedStyleRule. I started to copy stuff around, test some stuff and didn't fix code that much what was already there. Sry for that. I just wanted to get it working first. I will try to find anouther solution maybe with that what I already used for the HtmlCompletionProvider ` LexerUtils.followsToken(...`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1208547087

   I also thought to not hardcode the supported tags, but to use the validator rule for this, but this was to much for me. If this is wanted I can try to add this too, so this will be a bit more generic if other HTML tags are coming with the same validator rule.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1690679607

   After long round, I hopefully simplyfied it enough. I had a deeper look into existing hints like for extracting inline tag styles and seeing missing id rule and missing class rule, which has a visitor for finding this. @matthiasblaesing and @junichi11 please have a look and leave comments as necessary. Thx.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303750782


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import javax.swing.text.BadLocationException;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.csl.api.RuleContext;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.SINGLETON,
+            AddMissingAltAttributeRule.SINGLETON.getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.SINGLETON.getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            EventQueue.invokeLater(() -> {
+                try {
+                    Source source = Source.create(context.getFile());
+                    OffsetRange adjustContextRange = HtmlTagContextUtils.adjustContextRange(source.getDocument(false), range.getStart(), range.getEnd(), true);
+
+                    source.getDocument(false).insertString(adjustContextRange.getEnd(), " alt=\"\"", null);

Review Comment:
   `// NOI18N`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1304951684


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class HtmlTagContextUtils {
+    private HtmlTagContextUtils() {
+    }
+
+    public static OffsetRange adjustContextRange(final Document doc, final int from, final int to, final boolean beforeClosingToken) {
+        final AtomicReference<OffsetRange> ret = new AtomicReference<>();
+        ret.set(new OffsetRange(from, to)); //return the same pair by default
+        doc.render(() -> {
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(doc, from);
+
+            if (ts == null) {
+                //no html token sequence at the offset, try to
+                //TODO possibly try to travese the top level sequence backward
+                //and try to find an html embedding.
+                return;
+            }
+
+            Token<HTMLTokenId> openTag = Utils.findTagOpenToken(ts);
+
+            if (openTag == null) {
+                return;
+            }
+
+            int adjustedFrom = ts.offset();
+
+            //now try to find the tag's end
+            ts.move(to);
+            int adjustedTo = -1;
+            while (ts.moveNext()) {
+                Token<HTMLTokenId> t = ts.token();

Review Comment:
   Sorry, I'm wrong... This case need not check it(`ts.moveNext` is `true`) but it's harmless.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1958107582

   @matthiasblaesing so another research hear:
   * There are no CSS Hints/Suggestions/Fixes, etc, just the CssHintsProvider where the computeHints, computeSuggestions and computeSelectionHints method bodies are empty. I already have one CSS hint/suggestion on another branch, just to test smth but without any test.
   
   * The best implementation that I found is the PHP stuff for suggestions, but the problem is that I get a timeout when I try to run a PHP related suggestion test like this one locally: https://github.com/apache/netbeans/blob/master/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/InitializeFieldsSuggestionTest.java and on my branch, on the pipeline, the tests are not executed/skipped, but maybe because of the failing latte tests.
   
   * I also had a look into JsHintsProvider and JsHints. There is just one fix, changing the EcmaLevel but everything seems a warning. The tests will not work with suggestions. There will be a Parse exception, when I change the severity warning to a current_line_waning. Ok I really don't know whether I need to change smth else.
   
   Fazit: It seems PHP and maybe JS are better implemented in their *HintsProvider and I need to change the whole logik of the HtmlHintsProvider but JS also lacks of tests and suggestions are also not a big player for JS (not yet). Should this be part of this ticket? I guess not.
   
   I also think that we should make this somehow consistent for all CSL languages as good as possible. PHP uses Classes for like SuggestionRule, HintRule and ErrorRule, which just set the severity to the correct one and so on. So probably I will create another PR with the "fx" of the HtmlHintsProvider with using Tests.
   
   I think I ran into a rabbithole and yes, it is not your business but the code is a big mess and I want to rework it and hope to not break more than before. Any other thoughts/suggestions/hints? :D


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1511737617


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.HintFix;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.utils.HtmlTagContextUtils;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AddMissingAltAttributeHint extends Hint {
+
+    public AddMissingAltAttributeHint(HtmlRuleContext context, OffsetRange range) {
+        super(AddMissingAltAttributeRule.getInstance(),
+            AddMissingAltAttributeRule.getInstance().getDescription(),
+            context.getFile(),
+            range,
+            Collections.<HintFix>singletonList(new AddMissingAltAttributeHintFix(context, range)),
+            10);
+    }
+
+    private static class AddMissingAltAttributeHintFix implements HintFix {
+
+        private static final Logger LOGGER = Logger.getLogger(AddMissingAltAttributeHintFix.class.getSimpleName());
+
+        HtmlRuleContext context;
+        OffsetRange range;
+
+        public AddMissingAltAttributeHintFix(HtmlRuleContext context, OffsetRange range) {
+            this.context = context;
+            this.range = range;
+        }
+
+        @Override
+        public String getDescription() {
+            return AddMissingAltAttributeRule.getInstance().getDisplayName();
+        }
+
+        @Override
+        public void implement() throws Exception {
+            BaseDocument document = (BaseDocument) context.getSnapshot().getSource().getDocument(true);
+            document.runAtomic(() -> {
+                try {
+                    OffsetRange adjustedRange = HtmlTagContextUtils.adjustContextRange(document, range.getStart(), range.getEnd(), true);
+                    String tagContent = document.getText(adjustedRange.getStart(), adjustedRange.getLength());
+
+                    // Find last self-closing or non self-closing tag
+                    Pattern closingTagPattern = Pattern.compile("(/?>)");
+                    Matcher closingTagMatcher = closingTagPattern.matcher(tagContent);
+
+                    if (closingTagMatcher.find()) {
+                        int altInsertPosition = adjustedRange.getStart() + closingTagMatcher.start(1);

Review Comment:
   TBH, I didn't try PHP yet, will do it too. Thx for the hint. If I guess it correct, your example will not trigger the hint, because you already have the alt attribute. But yes It would be better to take the HTML token instead of just looking for the closing tag symbol with an regex.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1511734160


##########
ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java:
##########
@@ -4384,8 +4384,11 @@ protected ComputedHints computeHints(final NbTestCase test, final Rule hint, Str
                             }
                         }
                         if (HintsSettings.getSeverity(manager, ucr) == HintSeverity.CURRENT_LINE_WARNING) {
-                            manager.setTestingRules(null, Collections.EMPTY_MAP, testHints, null);
+                            manager.setTestingRules(null, testHints, testHints, null);
                             provider.computeSuggestions(manager, context, hints, caretOffset);
+                        } else if(HintsSettings.getSeverity(manager, ucr) == HintSeverity.ERROR || HintsSettings.getSeverity(manager, ucr) == HintSeverity.WARNING) {
+                            manager.setTestingRules(null, testHints, testHints, null);
+                            provider.computeErrors(manager, context, hints, new ArrayList<Error>());

Review Comment:
   No, not yet. I just thought that the pipes will show me the result and I just saw some failing tests of Latte. PHP where not triggert here at github inside my branch. I will just revert this change as you said and will try to implement a better logic into the HtmlHintsProvider as similiar as for PHP and JS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1356783096

   @Chris2011 something went wrong here. There is a massive set of changes where and you have conflict with master. This needs to be redone.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303756155


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AltAttributeVisitor.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.*;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AltAttributeVisitor implements ElementVisitor {
+    private static final String ALT_ATTR = "alt";
+
+    private final HtmlRuleContext context;
+    private final List<Hint> hints;
+    private final String tagToFindRegEx;
+
+    public AltAttributeVisitor(Rule rule, HtmlRuleContext context, List<Hint> hints, String tagToFindRegEx) throws IOException {
+        this.context = context;
+        this.hints = hints;
+        this.tagToFindRegEx = tagToFindRegEx;
+    }
+
+    @Override
+    public void visit(Element node) {
+        Source source = Source.create(context.getFile());
+        Document doc = source.getDocument(false);
+        final AtomicReference<List<InlinedStyleInfo>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<InlinedStyleInfo> found = new LinkedList<>();
+            result.set(found);
+
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, node.from());
+
+            if (ts == null) {
+                return;
+            }
+
+            OffsetRange range;
+            String tag = null;
+            String attr = null;
+            int startTagOffset = 0;
+            int endTagOffset = 0;
+
+            do {
+                Token<HTMLTokenId> t = ts.token();
+                if (t.id() == HTMLTokenId.TAG_OPEN) {
+                    tag = t.text().toString();
+                    attr = null;
+
+                    startTagOffset = ts.offset();
+                } else if (t.id() == HTMLTokenId.TAG_CLOSE_SYMBOL) {
+                    endTagOffset = ts.offset();
+
+                    range = new OffsetRange(startTagOffset, endTagOffset);
+                    //closing tag, produce the info
+                    if (tag != null && tag.matches(tagToFindRegEx) && attr == null) {
+                        //alt attribute found
+                        hints.add(new AddMissingAltAttributeHint(context, range));
+
+                        tag = attr = null;
+                    }
+                } else if (t.id() == HTMLTokenId.ARGUMENT) {
+                    if (t.text().toString().equals(ALT_ATTR)) {

Review Comment:
   Instead, use `TokenUtilities.textEquals()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303752919


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AltAttributeVisitor.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.*;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AltAttributeVisitor implements ElementVisitor {
+    private static final String ALT_ATTR = "alt";
+
+    private final HtmlRuleContext context;
+    private final List<Hint> hints;
+    private final String tagToFindRegEx;
+
+    public AltAttributeVisitor(Rule rule, HtmlRuleContext context, List<Hint> hints, String tagToFindRegEx) throws IOException {
+        this.context = context;
+        this.hints = hints;
+        this.tagToFindRegEx = tagToFindRegEx;
+    }
+
+    @Override
+    public void visit(Element node) {
+        Source source = Source.create(context.getFile());
+        Document doc = source.getDocument(false);
+        final AtomicReference<List<InlinedStyleInfo>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<InlinedStyleInfo> found = new LinkedList<>();
+            result.set(found);
+
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, node.from());
+
+            if (ts == null) {
+                return;
+            }
+
+            OffsetRange range;
+            String tag = null;
+            String attr = null;
+            int startTagOffset = 0;
+            int endTagOffset = 0;
+
+            do {
+                Token<HTMLTokenId> t = ts.token();

Review Comment:
   `t` : Need `null` check



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303757833


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AltAttributeVisitor.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.Hint;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.api.Rule;
+import org.netbeans.modules.html.editor.api.Utils;
+import org.netbeans.modules.html.editor.hints.HtmlRuleContext;
+import org.netbeans.modules.html.editor.lib.api.elements.*;
+import org.netbeans.modules.html.editor.refactoring.InlinedStyleInfo;
+import org.netbeans.modules.parsing.api.Source;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class AltAttributeVisitor implements ElementVisitor {
+    private static final String ALT_ATTR = "alt";
+
+    private final HtmlRuleContext context;
+    private final List<Hint> hints;
+    private final String tagToFindRegEx;
+
+    public AltAttributeVisitor(Rule rule, HtmlRuleContext context, List<Hint> hints, String tagToFindRegEx) throws IOException {
+        this.context = context;
+        this.hints = hints;
+        this.tagToFindRegEx = tagToFindRegEx;
+    }
+
+    @Override
+    public void visit(Element node) {
+        Source source = Source.create(context.getFile());
+        Document doc = source.getDocument(false);
+        final AtomicReference<List<InlinedStyleInfo>> result = new AtomicReference<>();
+
+        doc.render(() -> {
+            List<InlinedStyleInfo> found = new LinkedList<>();
+            result.set(found);
+
+            TokenHierarchy th = TokenHierarchy.get(doc);
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(th, node.from());
+
+            if (ts == null) {
+                return;
+            }
+
+            OffsetRange range;
+            String tag = null;
+            String attr = null;

Review Comment:
   This is not used as `String`. So, change this type to `CharSequence`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] Chris2011 commented on a diff in pull request #4485: Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303565819


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Chris
+ */
+public class HtmlTagContextUtils {

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1917079382

   Unfortunately I see that my changes break some PHP tests. Will dig into it again and would be happy to have someone that helps me break it down what I missed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#issuecomment-1927895147

   My gut feeling is, that the HtmlHintsProvider and the expectations of the CslTestBase/GsfHintsManager don't match. It seems suggestions were never really supported. It might be worthy looking into JS/CSS whether there are suggestions being checked. I'm not sure, that modifying CslTestBase is really a good idea.
   
   General comments:
   
   1. The unstable test you observed is because you dispatch the text change into another thread (`org.netbeans.modules.html.editor.hints.other.AddMissingAltAttributeHint.AddMissingAltAttributeHintFix.implement()`. That (a) makes it unstable and is IMHO wrong. I suggest to adjust to this:
       ```java
           @Override
           public void implement() throws Exception {
               BaseDocument document = (BaseDocument) context.getSnapshot().getSource().getDocument(true);
               document.runAtomic(() -> {
                   try {
                       OffsetRange adjustedRange = HtmlTagContextUtils.adjustContextRange(document, range.getStart(), range.getEnd(), true);
                       String tagContent = document.getText(adjustedRange.getStart(), adjustedRange.getLength());
   
                       // Find last self-closing or non self-closing tag
                       Pattern closingTagPattern = Pattern.compile("(/?>)");
                       Matcher closingTagMatcher = closingTagPattern.matcher(tagContent);
   
                       if (closingTagMatcher.find()) {
                           int altInsertPosition = adjustedRange.getStart() + closingTagMatcher.start(1);
   
                           // Check whether a space before alt is needed or not
                           boolean needsSpaceBefore = altInsertPosition == 0 || tagContent.charAt(closingTagMatcher.start(1) - 1) != ' ';
                           boolean isSelfClosing = closingTagMatcher.group(0).endsWith("/>");
                           String altAttribute = (needsSpaceBefore ? " " : "") + "alt=\"\"" + (isSelfClosing ? " " : ""); // NOI18N
   
                           document.insertString(altInsertPosition, altAttribute, null);
                       }
                   } catch (BadLocationException ex) {
                       // Ignore
                   }
               });
           }
       ```
       There is no need to do this on the EDT. The locking infrastructure of the documents should handle this.
   
   2. The `null` check in `CslTestBase#findApplicableFix` begins to make sense, when you write it like this: 
   
       ![image](https://github.com/apache/netbeans/assets/2179736/38711d1e-8dcf-40ae-a42f-33a2cd7597b8)
   
       The only difference compared to master is in line 4603, 4621 is only modified when comparing with your version.
   
       Then `org.netbeans.modules.csl.api.test.CslTestBase.applyHint(NbTestCase, Rule, String, String, String)` can be called with `null` as final parameter, which would invoke the found fix without checking for the description.
   
   3. Merges make it hard to compare against the base revision. Until this is changed incrementally/being reviewed I suggest to either not merge master or use rebases to cleanup/update.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Add HTML rule and hint+fix for missing alt attribute for tag img, applet and area [netbeans]

Posted by "Chris2011 (via GitHub)" <gi...@apache.org>.
Chris2011 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1511798981


##########
ide/html.editor/src/org/netbeans/modules/html/editor/hints/other/AddMissingAltAttributeHint.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.html.editor.hints.other;
+
+import java.awt.EventQueue;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;

Review Comment:
   Yes, those three are correct marked as not used, but your both other comments have different lines. That's why I'm asking. It was about the matcher, pattern, the exception, etc. That's why I was confused about it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists