Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SLDS Linter #101

Merged
merged 19 commits into from
Sep 13, 2017
Merged

Add SLDS Linter #101

merged 19 commits into from
Sep 13, 2017

Conversation

engai
Copy link
Contributor

@engai engai commented Sep 7, 2017

What does this PR do?

Adds SLDS Linter feature to Lightning Package

What issues does this PR fix or reference?

@W-4267770@

@vazexqi vazexqi mentioned this pull request Sep 7, 2017
5 tasks
@@ -1,5 +1,5 @@
# salesforcedx-vscode-lightning
Copy link
Contributor

Choose a reason for hiding this comment

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

@ruthemmanuelle - Could you review this README for @ayeshakmaz and @engai?

@vazexqi
Copy link
Contributor

vazexqi commented Sep 7, 2017

@engai @ayeshakmaz Could you take a look at your test to see why it's failing on windows? Could it be you are looking for a particular path and that you are using / instead of \?

@engai
Copy link
Contributor Author

engai commented Sep 7, 2017

@vazexqi Yes. It's trying to open ./assets/sfdx-simple. How would you suggest fixing this to work on Mac, Linux & Windows?

@vazexqi
Copy link
Contributor

vazexqi commented Sep 7, 2017

Try using https://nodejs.org/api/path.html#path_path_joint paths. You might want to also check to see that you are not using / in your code and not just the tests.

@codecov
Copy link

codecov bot commented Sep 8, 2017

Codecov Report

Merging #101 into develop will decrease coverage by 0.07%.
The diff coverage is 73.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #101      +/-   ##
===========================================
- Coverage    82.66%   82.58%   -0.08%     
===========================================
  Files           66       67       +1     
  Lines         1817     1832      +15     
  Branches       228      229       +1     
===========================================
+ Hits          1502     1513      +11     
- Misses         279      283       +4     
  Partials        36       36
Impacted Files Coverage Δ
...ackages/salesforcedx-vscode-lightning/src/index.ts 73.33% <73.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9a74ec...59f7bd4. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 8, 2017

Codecov Report

Merging #101 into develop will increase coverage by 2.2%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #101     +/-   ##
==========================================
+ Coverage    82.47%   84.67%   +2.2%     
==========================================
  Files           65       27     -38     
  Lines         1723      855    -868     
  Branches       219      129     -90     
==========================================
- Hits          1421      724    -697     
+ Misses         265       97    -168     
+ Partials        37       34      -3
Impacted Files Coverage Δ
...s/salesforcedx-apex-debugger/src/messages/index.ts 41.66% <0%> (-51.2%) ⬇️
...rcedx-vscode-core/src/commands/forceApexTestRun.ts
...sforcedx-vscode-core/src/commands/forceTaskStop.ts
...ode-core/src/commands/forceLightningEventCreate.ts
...core/src/commands/forceLightningComponentCreate.ts
...ges/salesforcedx-vscode-core/src/messages/index.ts
...orcedx-vscode-core/src/commands/forceSourcePull.ts
...cedx-vscode-core/src/commands/forceAuthWebLogin.ts
...ges/salesforcedx-vscode-apex/src/messages/index.ts
...vscode-core/src/predicates/salesforcePredicates.ts
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5757f0...5d090c4. Read the comment docs.

@engai
Copy link
Contributor Author

engai commented Sep 11, 2017

Paths look correct at the moment (some are glob patterns). The extension and tests run when tested in vscode on windows. However, they aren't running with the test script on Windows. Any ideas on what might be happening here?

@vazexqi
Copy link
Contributor

vazexqi commented Sep 11, 2017

@engai - Could you get a Windows VM and run the tests locally or add more logging for when the test fails?

The error is

lerna ERR! execute   1) SLDS Deprecated Class Name Should create deprecatedClassName command:
lerna ERR! execute      AssertionError: expected [ Array(693) ] to include 'deprecatedClassName'
lerna ERR! execute       at Object.<anonymous> (C:\projects\salesforcedx-vscode\packages\salesforcedx-slds-linter\test\deprecatedClassName.test.ts:27:28)
lerna ERR! execute       at Generator.next (<anonymous>)
lerna ERR! execute       at fulfilled (C:\projects\salesforcedx-vscode\packages\salesforcedx-slds-linter\out\test\deprecatedClassName.test.js:10:58)
lerna ERR! execute       at <anonymous>
lerna ERR! execute 
lerna ERR! execute 

``` but it's not clear why it can't find what it's looking for.

@engai
Copy link
Contributor Author

engai commented Sep 11, 2017

@vazexqi the test is essentially looking for our command within the workspace command list. This will only be there when the extension runs. Not sure what else to log in this case. The extension functions and tests pass when ran in VSCode on our VM, but the extension doesn't seem to run when ran from the test script.

The correct workspace is opened, but no syntax highlighting or linting appears.


it('Should create deprecatedClassName command', async () => {
const commandList = await vscode.commands.getCommands(true);
expect(commandList).to.include('deprecatedClassName');
Copy link
Contributor

Choose a reason for hiding this comment

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

@engai I guess you can log here to see what is the list of commandList on the autobuild and how that differs from the one you have locally. I am not yet sure why the test will fail since this seems to be a simple test.

@engai
Copy link
Contributor Author

engai commented Sep 11, 2017

screen shot 2017-09-11 at 2 38 54 pm

When working on mac and within vscode on windows, it's logging 45 more commands. These include ours and commands from git and sfdx:force. When running on the test script however, it's not logging these commands.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 11, 2017

@engai That is helpful. So we can at least narrow it down to the command not loading.

How are you running the tests locally? How does it differ from the appveyor.yml and travis.yml files? Could you be running it from a different directory?

On that note, I just noticed that your command doesn't follow the convention. Could you rename your command to sfdx.force.lightning.slds.deprecated.class.fix (or something similar)? We need to have some form of a namespace to ensure that command names do not collide and just deprecatedClassName is too generic.

@engai
Copy link
Contributor Author

engai commented Sep 11, 2017

@vazexqi To run via test script (Does not pass) - Following these steps in the salesforce-vscode directory:

  1. npm run bootstrap
  2. npm run compile
  3. npm run test (Sometimes ran from /packages/salesforce-slds-linter to ignore the other packages' tests)

Running in VSCode (Passes):

  1. Run Task > Bootstrap if changing anything in dependencies
  2. Launch Salesforce DX VS Code SLDS Linter Tests to run tests in ext. dev host

On a side note, currently unable to run tests via the script (was working yesterday). Seems like the script can't find a VSCode executable:

screen shot 2017-09-11 at 4 11 18 pm

Have you run into this problem? Looks similar to microsoft/vscode-extension-vscode#30

As for the command name, thanks for the heads up. I'll go ahead and change that.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 11, 2017

I just ran the tests locally and I'm able to produce the issue (on my Mac). I suspect that it's not loading something when run from the top-level.

  1. git clone git://github.com/forcedotcom/salesforcedx-vscode.git
  2. cd salesforcedx-vscode
  3. npm install
  4. npm run compile
  5. npm run test:without-system-tests (we don't need to run the UI tests to repro the issue)

await vscode.workspace.openTextDocument(res[0]).then(
document => vscode.window.showTextDocument(document)
res = await vscode.workspace.findFiles(
path.join('**', 'DemoComponent.cmp')
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be precise and look exactly for the .cmp you know has the deprecatedclassnames.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 11, 2017

@engai - Take a look at my latest commit where I moved your tests to the salesforcedx-vscode-lightning package. The tests need to be there since it depends on an actual activation event.

It runs when you do it from VS Code itself since you are loading all the packages (see .vscode/launch.json). But, when you run the tests from the command line, the tests only load the extensions for that package.

@engai
Copy link
Contributor Author

engai commented Sep 12, 2017

Ah that makes sense. The tests aren't passing within VSCode, but i'll work on that within the lightning tests

Copy link
Contributor

@vazexqi vazexqi left a comment

Choose a reason for hiding this comment

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

Also, don't forget to change the command name to something more descriptive.

"preLaunchTask": "Compile"
},
{
"name": "Launch Salesforce DX VS Code SLDS Linter Tests",
Copy link
Contributor

Choose a reason for hiding this comment

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

@engai - This one probably needs to be updated since I removed the ${workspaceRoot}/packages/salesforcedx-slds-linter/assets/sfdx-simple

res = await vscode.workspace.findFiles(
path.join('**', 'DemoComponent.cmp')
);
await vscode.workspace
Copy link
Contributor

Choose a reason for hiding this comment

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

@engai Since you open the file, you should probably have an after that closes it too (just to be tidy). So far it's not causing problems but as we have more tests in the future, I think it's good for each test to clean up after itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an after to close the editor. Looks like closeFile is deprecated.

@engai
Copy link
Contributor Author

engai commented Sep 12, 2017

@vazexqi Wasn't sure if it would affect the end-to-end tests, i'll remove mine and add the .cmp file to system-test.

Though .DS_Store was in the .git_ignore, i'll remove those as well.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 12, 2017

In one of my previous commits I already added the DemoComponent to the system-tests/assets folder. You should be able to see it.

@ayeshakmaz
Copy link

@vazexqi I'm looking in system-tests/assets, but not seeing that moved DemoComponent

@vazexqi
Copy link
Contributor

vazexqi commented Sep 12, 2017

@ayeshakmaz - Crap. I must have forgotten to commit it. One moment.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 12, 2017

@ayeshakmaz and @engai - I've added the DemoComponent.cmp now.

*
* If ommitted, we will assume _message.
*/
export const messages = {
Copy link
Contributor

Choose a reason for hiding this comment

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

@ruthemmanuelle - Could you take a look at these messages? There is a screenshot that shows where there are used in this PR.

@vazexqi
Copy link
Contributor

vazexqi commented Sep 12, 2017

@Sweetman - Here's another case where the travis builds just hangs.

@engai
Copy link
Contributor Author

engai commented Sep 12, 2017

@vazexqi I've added 3 tests to our slds-linter package. Let us know if there is anything else we should add. Appveyor build looks good as well.

it('Should send correct string', () => {

validateTextDocument('\n class"slds-button--brand" \n', 'uri', connection);
if (args) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@engai I think you should also assert that args is not null in the tests.
Because if it turns out that args is null, then if will skip the if(args) {...} and then the test will pass, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Pushed a fix to assert when null

* Code actions available on click
* Linter won't run if SLDS is included as a static resource in your project
* Code actions are available on click
Note: The linter won't run if SLDS is included as a static resource in your project.

![SLDS Linter detecting deprecated '--' class name syntax](https://raw.githubusercontent.com/forcedotcom/salesforcedx-vscode/ayesha/add-slds-linter/packages/salesforcedx-vscode-lightning/images/lightning_slds.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should take a new screenshot that includes the updated messages. We'll also need to update this path to use /develop/ instead of /ayesha/add-slds-linter/, but if we do that before merging in this PR the image won't display. It would be good if the resolution and text size of the screenshot approximately matched the other screenshots in this README.

fix_all:
'Fix all auto-fixable problems',
fix_error:
'Failed to apply SLDS Validator fixes to the document',
'Failed to apply SLDS Validator fixes to the document.',
Copy link
Contributor

@ruthemmanuelle ruthemmanuelle Sep 13, 2017

Choose a reason for hiding this comment

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

Do we have any idea what would have caused this problem? Can we suggest a solution? Also, I added a period, but if this error displays in the same format as the other messages in this section we can remove the period. VS Code seems to use sentence-case capitalization and no end punctuation for these contextual messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will only fail if the edit function doesn't successfully run. This wouldn't be a problem that the end user can fix. One thing we can suggest is filing an issue on Github with us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't display along with the other messages, so the period should be okay

break;
}
default: {
codeMessage = 'same problems';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this one is not done using nls.localize?

vscode.workspace.findFiles('**/staticresources/*.resource').then(
// all good
(result: vscode.Uri[]) => {
for (let i = 0; i < result.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Cosmetic: Is there a reason we use for(let i = 0...) instead of the for(const a of blah)?

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['plaintext', 'html'],
Copy link
Contributor

Choose a reason for hiding this comment

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

@ayeshakmaz - I think we only want HTML, right? No need for it to scan plaintext?

Choose a reason for hiding this comment

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

Yeah, we can take out the plain text option

@vazexqi
Copy link
Contributor

vazexqi commented Sep 13, 2017

Merging this in! Thanks @engai and @ayeshakmaz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants